1. Concept of Polymorphism
Polymorphism is a major feature of object-oriented programming. ReflectedProgramScalability also reflects the programCode. Simply put, an object can be operated in many ways based on different objects. Therefore, polymorphism is pinned on objects.
2. Application of Polymorphism
In object-oriented programming, polymorphism is mainly reflected through method overloading and coverage. The method is to send the same information to different objects and perform different tasks according to different objects.
3. constructor and Polymorphism
A class can have multiple constructor methods. When multiple class objects are created using different constructor methods of the same class, multiple objects are displayed, which reflects polymorphism.
4. Examples of multi-state application:
Design the program to explain the languages of several major countries in the world:
// Defined Public Class People { Public Void Speak () {system. Out. println ( "People speak" );}} // Define Chinese Public Class Chinese extends people { Public Void Speak () {system. Out. println ( "Chinese speak Chinese" );}} // Define Americans Public Class American extends people { Public Void Speak () {system. Out. println ( "Americans speak English" );}} // Define Japanese Public Class Japanese extends people { Public Void Speak () {system. Out. println ( "Japanese speak Japanese" );}} // Define applications Public Class Yingyong { Public Static Void Main (string [] ARGs ){
People les; Chinese = New Chinese (): // Create a Chinese American = New American (): // Create Americans Japan =New Japan (); // Create Japanese Les = Chinese; Les. Speak (); Les = American; Les. Speak (); Les = Japan; Les. Speak ();}}
Finally, the result of running the program is:
Chinese speaking
Americans speak English
Japanese speak Japanese
Therefore, this fully reflects the behavioral polymorphism, also makes the program level clear, in line with the object-oriented programming philosophy!