Java Basic Knowledge Essence Summary

Source: Internet
Author: User
Tags abstract constant constructor final implement inheritance interface variables
Essence 1 Initialization of objects (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) Static variables of the main class in the initialization program of a static object are initialized before the main method executes. When you create an object for the first time, all of the static variables in the class are initialized, and the first time you access a static object of a class (note that no such object is created at this time), all static variables are also initialized in the order in which they are in the class. 2. When inheriting, the initialization process of the object (1) The superclass of the main class initializes the static member in order, regardless of whether the static member is private or not. (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 you initialize a Non-static object for this superclass before calling the default constructor method for each superclass. (4) Initialization of non-static members of the main class. (5) Invoke the constructor method of the main class. 3. The construction method (1) class may not have a constructor method, but if there are multiple construction methods, there should be a default constructor, otherwise, when inheriting this class, it is necessary to explicitly call one of the Non-default constructor methods 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 must be the first statement. 4. For public, private, and protected (1) classes that are not public decorated, the conditions that can be accessed by other classes are: A. Two classes in the same file, B. Two classes in the same folder, C. Two classes 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) abstract class cannot create 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 (in subclassesMethod with the same name cannot appear in. (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 members can be final or not. 7, interface interface (with implements to implement Interface) (1) All data in the interface is static and final, that is, statically constant. Although you can use these two keyword modifiers, you must give Chang an 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 front, the interface is written back, and the interface is separated by commas. (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 the interface inherited by this interface, all the methods in the interface must be implemented in the class. 9, the interface embedded (1) Interface embedded class, you can use private decoration. At this point, the interface can only be implemented in the class in which it is located, and other classes cannot be accessed. (2) The interface in the embedded interface must be public. 10. The class's embedded (1) class can be embedded in another class, but not embedded in the 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 = 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 be invoked automatically, so it is necessary to explicitly call the constructor method of the superclass in the constructor 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 constructor method can also be written like this: C (a) {    a.sUper (); } //Use this construct method to create an object, written as C C = new C (a); A is the object of a. 11, Exception class Java in addition to the RuntimeException class, other exceptions must be captured 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.