1. Combination
- Place object references for other classes in the new class.
3. Inheritance
- Keyword extends a class inherits a base class and automatically obtains all the fields of the base class (including field reference inner classes) and methods, not including private, which does not require a base class object reference. Inheritance is equivalent to an extension of the base class, since the base class has it all, adding some additional fields and methods (or Overwrite methods).
4.super
4.1 super.f () invokes the F () method of the base class.
The super (args) in the 4.2 constructor calls the base class constructor and can only be in the first row.
4.3 Because the constructor is overloaded and the default constructor does not exist, and when the subclass object is created, the base class constructor must be called, and if you do not use super, call the base class default constructor, and the base class constructor constructor is overloaded, so you will get an error. So the base class constructor is overloaded after the subclass is to be displayed in the constructor using super to call the base class constructor.
5. Agent
- Creates a member object in a class and exposes the methods of that object.
- The role of the agent or when to use a proxy: we only want to use some subset of the method of the member object. (although this can be done through inheritance and access permissions settings)
6. When to use combination or inheritance
- Composition: Implement existing class functionality in a new class, rather than an existing class interface.
- Inheritance: Develop a special version of an existing class.
7.final
7.1 Final cannot change data. The final reference cannot point to another object, which also applies to the array, which is also the object, but the object content can be changed and cannot be changed when the reference is pointed to.
7.2 Final parameter: The parameter is a reference and cannot be changed to a point, and the parameter is the base data type and the value cannot be changed.
The 7.3 final method can be inherited but subclasses cannot overwrite, and all private methods are implicitly final. (Private method is not accessible by the class, the final method does not necessarily see what it is)
7.4 The final class has no subclasses and cannot be inherited.
8. Main method
8.1 You can set the main method in the class so that the unit test runs the class separately.
8.2 Except for constructors, other methods require an object invocation to execute, and the main method does so, and the main method is not called when the object is created, and the main method is called only when the Java class command is executed.
8.3 A separate class without the Main method is not able to run, the main method when the program runs the portal.
Knowledge Points:
- Each non-basic class object has a toString () method that prints the object reference and outputs the method's return value.
- The default constructor permission is the same as the class permission, and the constructor with no write permission is the package access permission.
- Access rights who can access it? Who is referring to the class, not the object.
Java programming thought note Seventh chapter reuse class