Method overrides:
The base class method identifies the virtual keyword, the subclass (inheriting Class), in the method override to identify the override keyword.
The overridden method must be the same as the type of the base class, such as the method name, return, and accept parameters.
public class Class1 {public virtual void Show (int i) {...} } public class Class2:class1 {public override void Show (int a) {...} }
The new method overrides:
public class Class1 { protected virtual void Show (int i) {...} } public class Class2:class1 {public new int show (int a) {...} }
The new declaration defines its own method with the same name. The return type, access type can be different from the base class with the same name method.
If the accept parameter differs from the base class method with the same name, the new keyword is redundant, which is equivalent to a general override (the base class has no same method, and no hidden method).
Override the method body that overrides the base class method (hidden method), and new overrides the base class with the same name method (the receive parameter is the same).
Terminating inheritance:
Terminates the inheritance identity sealed. The following code compiles an error and Class2 cannot inherit the enclosing class Class1
public sealed class Class1 {public virtual void Show (int i) {...} } public class Class2:class1 //{ //public override void Show (int a) // {...} //}
Call the base class constructor:
The compiler calls the base class constructor first, and then calls the inheriting class constructor.
public class Class1 {public Class1 (int i, string j) {...} } public class Class2:class1 {public Class2 (int i,string j,object obj): Base (i,j) {...} }
The above is the C # supplements of the Small Knowledge (iv): Inherited content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!