Overloads of the method:
Specifies that a method can have different implementations, but the name of the method is the same. Such as:
// the same man, the method . Public int Man (int age,int name) { ...} // overloaded Public int Man (int age ) { ...}
The presence of overloads can be a common method to use when the main function calls the class, depending on the object's desired flexible invocation.
Methods of hiding:
When a subclass has exactly the same method as the parent class, the method with the same name is hidden from the parent class.
If it is intentionally hidden, you should write the New keyword in the same way, such as:
class parent{ public void HiDef () { System.Console.WriteLine ( Parent.hidef () ); }} class child:parent // { public new void HiDef () { System.Console.WriteLine ( Child.hidef () ); }}
The above code runs as "child.hidef ()" when calling the child class.
If you want to invoke the HiDef class of parent, you need to use the base keyword, which is:
base. HiDef (); // calling a method that the parent class is hidden
The hiding of general methods is seldom used.
Methods are overridden with virtual methods:
This is equivalent to hiding the method, but hiding the need to cast, in order to solve the trouble, with the keyword virtual in front of the parent class, indicating that this is a virtual method, the subclass can be overridden by the same method with the keyword override this method, indicating that the parent class with the same name method is overridden.
For example: People have a "talking" feature, which we define in parent Ren:
class ren{ virtualvoid Shuohua ()//The virtual method of the parent class { Console.WriteLine ( " can speak ");} }
We make men a subclass of Ren, and rewrite the words "speak English" on the Inside:
class man:ren{ publicoverridevoid Shuohua ()//Override Parent class method { Console.WriteLine (" speak English ");} }
The "virtual method invocation" attribute of an object-oriented language enables us to perform different operations at run time based on the object type, using only the same statement.
5. Simple application of object-oriented and WinForm (method overloading, hiding, overriding and virtual methods)