Today, I learned some of the content of polymorphic, abstract classes, and interfaces.
In the actual operation, the same parent class is inherited, but the method in the parent class does not apply to any subclass, then the subclass is required to rewrite the body of the method.
When overriding a member method, the parent class is required to consent to a subclass that can rewrite its own method:Virtual -virtual method; Subclasses can only override methods that are allowed by the parent class , overriding the virtual method: Override-Overrides the virtual method.
A base class is relative to a derived class, and all classes can be treated as parent classes and can have virtual methods.
Abstract class: Abstraction
Abstract classes are meant to be inherited. All the methods in the ordinary class become virtual methods, no one uses the most basic method, all need to rewrite, then do not need so laborious to the ordinary class of the method body is written, but directly defined as abstract class, and are written abstract methods.
I think that abstract class is to put the project we do, the whole into a large class, its primary goal, not to achieve what function, but to limit the project to a scope, under this precondition to expand our project, the concrete module of the project to inherit this abstract class, and then to write the specific functions of the subclass. In an abstract class, you can have an abstract method, or you can have an ordinary method. Abstract methods only need to declare the name and return type of the method, and what the body of the method is, and inherit the past and implement it by subclasses.
Cases:
public abstract class Ren { public abstract string Chifan (); public abstract string Shuijiao (); public virtual string Shuohua () { return I can talk! ; } }
Interface:interface
Interface is to make the class we write more perfect, to complement the classes we write. In the interface, only the abstract method can be written, no specific method can be written, all the content needs to be implemented in the subclass.
Such as:
Public Interface Gongzuo { string Jineng (); string Didian (); }
The subclass's format when inheriting abstract classes and interfaces:
Public class Nanren:ren, Gongzuo, yule{}
Object-oriented polymorphism, abstract classes, and interfaces