<1>
Using system; using system. collections. generic; using system. LINQ; using system. text; namespace list {Class A {} Class B: A {public a mymthod () {// you can see that the return value type of this mymthod () method is clearly a type, why is no error returned if a B-type object is returned? Return new B (); // because B is a subclass of type A, the subclass object can be implicitly converted to the parent class object. Here we have implicitly converted type B to type A and returned it. Therefore, no error is reported.} Class program {static void main (string [] ARGs) {A = new A (); B = new B (); A = B; // a subclass object can be assigned a value to a parent class Object // B = A; // a parent class object cannot be assigned to a subclass object B = (B) A; // For example: if the parent class is a "person", it has two sub-classes: A "Chinese" class, A "American" class // That is to say, a new Chinese object "bruce lee" New an American object "Obama" // a new "person" object "person 1" // subclass target: Bruce Lee ", "Obama" can certainly be assigned to "person", the parent object 1. Because "person 1" can be Chinese or American, as long as it is a person. Here you can give me a "bruce lee" or "Obama. // The parent class Object "MAN 1" is assigned to the subclass object "bruce lee" or the subclass object "Obama. // Because "bruce lee" is a Chinese type, the Chinese type can only receive the Chinese type, so when you assign a "person" type object to the "Chinese" type object, an error occurs. If you want a Chinese person, you can give me one person. How do I know if your "person 1" is Chinese? You may also be American or German. Right. // Unless you specify to me that this person must be a Chinese person. "Bruce Lee" = (Chinese) "MAN 1 "}}}
Inheritance (the process of [mutual conversion] Between subclass objects and parent objects)