Multi-State (one of object-oriented features ):
The function itself has polymorphism, and a specific thing has a different embodiment.
Embodiment: parent class reference or interface reference points to its own subclass object. // Animal A = new CAT ();
Benefits of polymorphism: improved program scalability.
Disadvantages of polymorphism: when the parent class references a subclass object, although it improves scalability, it can only access the methods in the parent class and cannot access the special methods in the subclass. (You cannot use the features generated later in the early stage, that is, access restrictions)
The premise of polymorphism:
1: It must be related, such as inheritance or implementation.
2: There are usually overwriting operations.
The emergence of polymorphism is also changing in mind: Previously, it was to create an object and direct the object to do things. With polymorphism, we can find the common types of objects and directly operate on them to do things. In this way, we can direct a batch of objects to do things, that is, through the operation of parent classes or interfaces.
Class {
Void lecture (){
System. Out. println ("Enterprise Management ");
}
Void phishing (){
System. Out. println ("phishing ");
}
}
Class instructor extends {
Void lecture (){
System. Out. println ("Java ");
}
Void movie (){
System. Out. println ("watching movies ");
}
}
Class {
Public static void main (string [] ARGs ){
Miss Bi ye x = new Miss Bi (); // the target of Miss Bi is upgraded to the type of Miss bi.
// X. Lecture ();
// X. Watch a movie (); // error.
Instructor Bi y = (Instructor Bi) x; // forcibly converts the master Bi type to the master Bi type.
Y. Watching movies (); // In polymorphism, all the child objects from the beginning and end are changing their types.
}
}
If you want to use the special method of subclass object, how can you determine which specific subclass type the object is?
You can use the keyword instanceof; // you can determine whether the object implements the specified interface or inherits the specified class.
Format: <object instanceof type> to determine whether an object belongs to the specified type.
Student instanceof person = true; // student inherits the person class
The characteristics of polymorphism in the Child parent class:
1. member variables: In polymorphism, the Child parent class member variables have the same name.
During Compilation: Refer to whether the class to which the referenced variable belongs has called members. (No object is generated during compilation, only check for syntax errors)
Runtime: it is also a member of the class to which reference variables belong.
One simple sentence: no matter the compilation and running, the member variables refer to the member variables in the class to which the variables belong.
It is easier to remember: For member variable compilation, SEE = left, and for running, SEE = right.
3. Static functions.
Compilation period: it refers to whether the referenced variable belongs to the class and whether there is a call member.
Runtime: it is also a member of the class to which reference variables belong.
Why? Because static methods do not belong to objects, they belong to the class of the method.
Call static method references the reference of the class that calls the static method of the class.
Put simply: static functions ASP. NET + unity development,. Net training, and hope to communicate with you! ----------------------