Anonymous objects
Packaging
constructor function
This
1, Anonymous object: Do not create object names, directly use the object, after the use of the anonymous object will disappear
New Student (). Start ();
2, Encapsulation: Hide some detailed details, using some public methods, is the use of external classes
private int A;
private void A ();
3. Constructor function
To create a method with the same public as the class name in a class
public Student (); This construction method is created automatically when the object is created, and if you create a constructor manually, the default method of the system disappears.
Public Student (int a);
4, this
Represents the method or property of the class itself.
You can also use this in the constructor method, but you will get an error if you use the method before other statements.
Note: The use of this in the constructor method cannot be called by a colleague two dog miscellaneous methods, as the following example is wrong.
Public Student (String name) {
This (a, b);
}
Public Stuent (String Name,int age) {
This (name);
}
Java Learning Note 2