JAVA Basic Knowledge Summary __java

Source: Internet
Author: User
Java Basic Knowledge Essence Summary

1, the initialization of the object
(1) Initialization of Non-static objects
When an object is created, all data members of the class in which the object resides are initialized first.
Base type: type int, initialized to 0.
If object: These objects are initialized sequentially.
※ when all class member initialization is complete, the constructor of this class is called to create the object.
The purpose of the construction method is to initialize.
(2) Initialization of static objects
The static variables of the main class in the program are initialized before the main method executes.
Not only the first time an object is created, all the static variables in the class are initialized, and the first access to a class (note
When a static object is not created for such an object, all static variables are also initialized in the order in which they are in the class.
2, when inheriting, the initialization of the object process
(1) The superclass of the main class initializes the static member sequentially, regardless of whether the static member is private or not, from high to low.
(2) Initialization of static members of the main class.
(3) The superclass of the main class is called by the default constructor method from high to low. Note that the default construction of each superclass is called
method, the initialization of this superclass for Non-static objects is preceded.
(4) Initialization of non-static members of the main class.
(5) Invoke the constructor method of the main class.
3, about the construction method
(1) A class can have no construction method, but if there is more than one construction method, there should be a default constructor, otherwise, when inheriting this class, it is necessary to explicitly call a Non-default construction method of the parent class in the subclass.
(2) In one construction method, only one other construction method can be invoked, and the statement that calls the constructor method must be
The first statement.
4, about public, private and protected
(1) Classes that are not decorated by public, and that can be accessed by other classes: A. Two classes in the same file, B. Two classes
In the same folder, C. Two classes are in the same package.
(2) Protected: Inheriting classes and classes of the same package are accessible.
(3) If the construction method is private, an object of that class cannot be created in the other class.
5. Abstract class
(1) An abstract class cannot create an object.
(2) If a method in a class is an abstract method, then the class must be an abstract abstraction class.
(3) classes that inherit abstract classes must implement abstract methods in the abstract class.
(4) Abstract classes can have abstract methods, and can also have a non-abstract method. An abstract method cannot be private.
(5) Classes that indirectly inherit an abstract class may not give the definition of an abstract method.
6, Final keyword
(1) An object is a constant and does not represent a member of an object that cannot be transformed, and can still be manipulated by its members.
(2) Constants must be assigned before they are used, but they can only be initialized in the construction method except for the initialization of the Declaration.

(3) The final modified method cannot be reset (a method with the same name cannot occur in a subclass).
(4) If the declaration of a class is final, then all the methods are final, regardless of whether they are final modified, but the data
A member may be final or not.
7, interface interface (with implements to implement interface)
(1) All of the data in the interface is static and final, which is still constant. Although you can not use these two keywords to decorate
, but must give Chang initial value.
(2) The methods in the interface are public, and in implementing the interface class, the implementation method must be public keywords.
(3) If you use public to decorate an interface, the interface must be the same as the file name.
8. Multiple inheritance
(1) A class inherits a class and an interface, then the class must be written in the front, the interface is written in the back, and the interface is used to tease
Number separation.
(2) Multiple inheritance between interfaces, attention to the use of keyword extends.
(3) A class implements only one interface, but not only to implement all the methods of this interface, but also to implement this interface
The method of an inherited interface in which all the methods in the interface must be implemented in the class.
9, the interface embedding
(1) In an interface embedded class, you can use private adornments. At this point, the interface can only be implemented in the class in which the other class does not
able to access.
(2) The interface in the embedded interface must be public.
10, the Class of embedding
(1) A class can be embedded in another class, but it cannot be embedded in an interface.
(2) in static methods or other methods, it is not possible to create internal class objects directly, which need to be obtained by means.
There are two kinds of means:
Class A {
Class B {}
B Getb () {
b b = new B ();
return b;
}
}
static void M () {
A A = new A ();
a.b ab = A.getb (); or a.b ab = A.new B ();
}
(3) A class inherits the inner class of another class, because the superclass is an inner class, and the construction method of the inner class cannot automatically
is invoked, so that the constructor method of the superclass needs to be explicitly called in the constructor method of the subclass.
Take the example:
Class C extends A.b {
C () {
New A (). super (); This sentence implements a call to the inner class constructor method.
}
}
The construction method can also be written like this:
C (a) {
A.super ();
///Use this constructor to create an object to be written as C C = new C (a); A is the object of a.
11. Exception class
In Java except for the RuntimeException class, all other exceptions must be caught or thrown

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.