Thinking in java notes

xiaoxiao2021-03-31  200

1: Non-Static functions and data cannot be used directly in the Static function.

2: Only the data member is automatically initialized, and the variables in the function will not initialize.

3: This represents this object, the current object; uses another constructor in the Constructor, but cannot use the second THIS (Arg), and must be placed first; this.s = S;

Super.Method (ARGS) in the normal inheritance class;

The constructor is called the parent class constructor to use Super (args), and can only be called once in the first line.

If a non-DEFAULT constructor is written in the base class, the subclass must call Super (ARGS);

As long as you write a constructor, no matter whether you have no ginseng, there will be no default constructor. When you generate this instance, you need to call your own constructor.

Habits: Write the constructor, the subclass actively calls the parent class constructor.

4: Initialization Order (1) Object Generation or Static Data Member or Function Call, Load Class File

(2) Initialization All static data / functions are not used by it

(3) Initializing Primitiva and References

(4) Initialization at the definition

(5) Perform constructor, only NEW is called, simply use STATIC

5: Direct initialize when a data member is defined in the class and cannot be initialized by branch.

That is: ClassName AA;

AA = new classname ();

INT i; i = 1;

Must INT i = 1; ClassName AA = New className ();

But Int i; classname aa; {i = 1; aa = new classname ()}

Or Static Int i; StAIC ClassName AA;

Static {i = 1; aa = new classname ()}

6: array:

Do not make a size when defined and initialized

(1) Integer [] a = new integer [] {new integer (1), new integer (2),}

(2) Integer [] a = {new integer (1), new integer (2),}

(3) Integer [] a;

A = new integer [] {new integer (3), new integer (3), new integer (3),}

In the class, it can be defined and explicitly initialized; it can also be defined, but the initialization is initialized, including constructor; in the method, it can be defined and then initialized. This property is limited to the method

The following error

a = new integer [];

A = {NEW INTEGER (3), New Integer (3), New Integer (3),}; A is a reference (4) integer [] A;

a = new integer [3]; specifying its size, only one initialization

a [0] = new integer (2);

(5) Integer [] a = new integer [3]; specifying its size, only one initialization

a [0] = new integer (2); array Copy, Fill, Sort, binarysearch, Equal all have static methods in java.util.Arays System.Arraycopy ()? ? ? ? ? ? ? ? ? ? (6) Pay attention to most groups

Integer [] [] a;

a = new integer [3] [];

For (int i = 0; i

a [i] = new integer [3];

For (int J = 0; j

a [i] [j] = new integer (i * j);

}

}

7: The class is only two kinds of public and default. Methods and attributes have four kinds.

8: You cannot inherit the structure of the constructor is private

9: The variables defined in the function can only default; 10: The constructor of the class is private, and the STATIC function returns to the class by defining the Static function of the class, or the STATIC variable of the class, the latter can only produce a class object.

201 garbage collection

10: The definition of constants is often public static final, which may be a compiler constant, which may be an execution period. Final variables that are not initialized at the definition must be initialized in the constructor. When the final parameter is equivalent to the PL / SQL IN, the normal condition is in Out

The final function is that the subclass cannot be changed, and the Final class cannot be inherited.

11: When the class is loaded, the Static variable, STATIC block is initialized, and the Static method is called when used.

12: Initialization Sequence: Load base class, subclass à base class, STIC initialization à Variable Settings Settings and Nullà If there is new, the primary class constructor is initialized after the definition is the base class constructor, the subclass constructor.

à is just using Static variables, and the variable definition is still not initialized. First constitute a base class talents.

13: Do not call non-final and private type functions when the constructor and the constructor are initialized, otherwise it is possible to call the methods overwritten in the subclass. P241

A class is not a child, but actually calls the actual subclass when using the parent class.

14: The data member in the interface automatically produces a constant group for public static final, and the function is automatically public

15: Nested Private Interface in class can be implemented as a public, private class in a nested class, but such a class that implements the Private checkbox interface can only be manipulated by a class of its use. P259

16: The peripheral and peripheral interface can only be public and default, and the inherently hidden can be any.

17: The function in Interface is automatically used for public. When INTERFACE is implemented as public, the data in Interface is public static final, but it cannot be Blank Final, because Blank Fiel needs to initialize in the constructor. Can be an execution period initialization Final, such as Final INT i;

i = new random (). Nextint ();

17: The interface nested in the interface can only be public

17: You can expand Interface17 by extends: Anonymous Class can implement interfaces, can inherit, but the parent class of anonymous class has a non-default constructor, simply incorporate parameters when NEW can be introduced. Because of the unwilling function, the way to initialize the entity {INT A; A = a;

18: Other objects used in anonymous class must be named Final

19: Non-Static Inner Class object has a reference to the Outer Class, so you must have an Outer object when you generate a non-Static Inner Class, and you can access any peripheral objects. The Static Inner Class object does not require a peripheral object when the peripheral object is generated, and it is not possible to access the peripheral object.

20: Internal hidden category of Private implementation, after the reference is obtained in another type, it cannot be converted downward after reference to the interface.

21: Inheriting the hidden class, because the Outer class is required, the constructor of the inner hidden subclass requires a reference to a periphery. When inheriting the Outer class, the overwriting insiders have no effect, although there is no effect, but it can also be clearly pointed out: Inner class in the subclass inherit the Inner class in the parent class, and can be the same name, in this case, the father The INNER class generated in the class will not spread, that is, the INNER class in the subclass is generated. See P275

22: Non-STATIC in the outside must have an OUTER object. After you have an Outer object, you can pass the function or new, but you cannot directly NEW PRIVATE type. If the internal hidden class implements other interfaces, or inherits other classes, the transformation cannot be enforced down.

When you generate an Inner class object, you must have a reference to the Outer object, except for the Statc Inner class.

When you get an Outer class in Inner, you only need OuterClassName.THIS;

When you use the Static Inner class object in an outside, you can define a Static function that returns a Static Inner class object in the Outer class, and then call this function to get the Static Inner class.

Public class untricled2 {

Static class a {

INT i = 4;

}

Class B {}

A bb () {

// system.out.println (unstem2.this); àthis is non-Static

// new usd2 (). New a (); àa does not need Outer class, no

Return new a ();

}

B cc () {

New uns (). New b (); à must have Outer class,

Return new b (); à, so you can directly New, because you already have an Outer class object when CC ()

}

Public static void main (String [] args) {

A SDFS = New A ();

// new usd2 (). New a (); à no need, you can't have an Outer class object

// new b (); à no Outer object

B DD = New Untitled2 (). New b ();

}

}

Class mihu {

Static void lasjf () {

// new a ();

System.out.println (Untitled2.bb (). I); à Need BB () is static

// new b ();

NEW unTID2 (). New b ();

NEW Untitled2 (). cc ();

}


New Post(0)