Let's take a look at the Java situation.
Public class program1 extends program0 {
Public string name = "son ";
/**
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
Program0 P = new program1 ();
P. Method (); // output: subclass
System. Out. println (P. Name); // output: Father
}
@ Override
Public void method (){
System. Out. println ("subclass ");
}
}
Class program0 {
Public string name = "father ";
Public void method (){
System. Out. println ("parent class ");
}
}
All member methods of the Java class can be inherited by default. If the access permission is not private. When an instance of a subclass is assigned to a variable of the parent class, the override method is called using the variable. What we actually call is the subclass method. But the variable is the parent class. This is what we usually call it. member variables, static members, and static methods are bound to classes, and member methods are bound to instances.
C # situation
All member methods in C # cannot be inherited by default, which is the opposite of Java. Then, the method binding starts recursion from the base class (the base class here refers to the class at the top of the hierarchy, but the class declared by the variable, if the method of the base class is visual and the override of the direct subclass is performed, the method of the direct subclass is called, otherwise, when the base class method is non-virtual or virtual, but the direct subclass does not override, the base class method is called.