1. Three major features of the Java language: inheritance, encapsulation, and polymorphism.
Inheritance: A method of reusing a class that can omission a lot of code;
Encapsulation: Creates a new data type by merging features and behaviors. "The data type" is exactly the same as the 8 "basic data Types" provided by Java itself. Java expands data types by encapsulating this way. 】
Polymorphism: Eliminates the coupling relationship between the innovative data types.
2, early binding: Static and final methods are pre-binding (binding and executing at compile time);
3. Late binding: In addition to the static and final methods in Java, it is late binding (as mentioned earlier, the private method belongs to the final method).
4. Polymorphism:
Only late-bound methods have polymorphism "other, such as: Early binding method, Domain (field) and so on do not have polymorphism";
In other words, polymorphism is an object-oriented feature (one of three major features). And the Java language is not a complete or purely object-oriented language, like static these are anti-object things.
5. Constructor initialization
The constructor of the parent class must be called, first initialized for the parent class, gets the object (child object) of the parent class, and then initializes itself.
6. Transformation:
Upward transformation: new methods are lost;
Downward transformation: Requires type checking.
Example:
1 PackageLKL;2 3 Public classCycle {4 Public intwheels () {5 return0;6 }7 }8 9 Public classTricycleextendscycle{Ten Public intwheels () { One return3; A } - } - the Public classBiCycleextendscycle{ - Public intwheels () { - return2; - } + } - + Public classUnicycleextendscycle{ A Public intwheels () { at return1; - } - } - - Public classRidetest { - Public intWheels (Cycle cy) { in returncy.wheels (); - } to Public Static voidMain (string[] args) { +Ridetest RT =Newridetest (); - ///behaves differently depending on the different sub-classes passed in, called Polymorphic theSystem.out.println (Rt.wheels (NewUnicycle ())); *System.out.println (Rt.wheels (NewBiCycle ())); $System.out.println (Rt.wheels (NewTricycle ()));
Java Programming thought Learning (vi) polymorphism