Reuse class:
Compost: In the new class, create an old class object, the multiplexed only the function of the code is not its form.
Inheritance: The whole process is accepted in the form of the old class, add a new code.
Compost's grammar:
Introduction to a special method to TOSTRING () All non-Primitive objects have this method, when the compiler needs a string and it is an object, the compiler will automatically call this method.
Inheritance's grammar:
The base class will initialize before the derived constructor is accessed. The constructor is divided into parameters and without parameters. If the selected base class constructor is a parameter, you must use the Super keyword and when the parameters are clearly invoked the base class constructor.
Use synthesis or inheritance: Synthesis for new classes to use the functions of the old class, rather than their interface. The object is embedded in and use it to implement the function of the new class, but the user sees the interface of the new class, not the interface of the object embedded. Therefore, you have to embed the old class object in the new class. Inheriting the expression of "IS-A" is expressed, while synthesizing the relationship between "HAS-A".
Upload: Pass the derived class to the base class is the upload along the inheritance. Upload is always safe, because you convert a more specific type to a general type.
-----------------------
Class Instrument {
Public void play () {system.out.println ("play");}
Static void Tune (Instrument i) {
I.Play ();
}
}
Public class wind extends inStrument {
Public static void main (String [] args) {
Wind flute = new wind ();
Instrument.Tune (flute);
}
}
-----------------------
Final Keywords: (not allowed)
Final Data:
Final Reference: Initialization Once the Reference is connected to an object, you cannot point to other objects.
Final Method: The "lock" is prohibited from registration.
Final Class: It is forbidden to inherit, blood blur is not possible.
Initialization and class loading:
Perfect.