I. abstract classes/abstract methods
1. abstract methods are modified with abstract.
2. Abstract METHODS cannot have method bodies (nor can there be large arc ).
Eg:
}
3. abstract methods must be in abstract classes.
4. abstract classes cannot be instantiated. Abstract members have no method bodies.
5. The subclass must override the abstract method of the parent class.
6. the abstract method of the parent class cannot be called through the base keyword in the subclass.
7. The abstract method is "do not do", but defines such behavior, but the specific implementation is handed over to the subclass.
8. abstract classes can have non-Abstract members. To inherit from them.
9. The abstract class can have virtual methods.
10. Usage of abstract classes: 1) The subclass must override the method of the parent class. 2) There is no need to instantiate the parent class.
11. abstract classes are inherited for polymorphism.
12. Abstract members cannot be private, because sub-classes cannot be rewritten without methods.
Eg1:
Console. WriteLine (Main (Computer c = UDisk =}View Code
Eg2:
Console. WriteLine (Console. WriteLine (Main (Console. WriteLine (str = NoteBook book = NoteBook GetANoteBook (type = returu (type =}View Code
Ii. ToString/Equals Method
Eg:
Name {; Main (Person p = Person () {Name = Person p1 = Person () {Name = B = p. equals (p1); Console. writeLine (p); Console. writeLine (B); str0 = str1 = B = str0.Equals (str1); Console. writeLine (B );}View Code
Iii. Interfaces
1. Define an interface with an interface. It is a special abstract class and cannot be instantiated.
2. The members do not need to add abstract or access modifiers. The default value is public abstract.
3. interfaces can only define attributes, methods, indexers, and events.
4. The class that implements the interface must implement all the members of the interface.
5. When implementing interface members, the implementation class does not need to write the override keyword.
6. interfaces are purely implemented to standardize classes.
7. You can find the parent class and want to inherit from the Child class to use the abstract class. Multiple classes have the same method, but no parent class can be found. You can define the method in the interface to implement these classes.
8. A class can only inherit one parent class, but multiple interfaces can be implemented. The parent class should be written in the first position, which solves the single-root problem of the class to a certain extent.
9. interfaces can inherit interfaces.
10. The member in the interface can be implemented as an abstract or virtual method, so that the sub-class of the implementation class can be implemented.
11. The display implementation interface is used to solve the problem of Method Name Conflict. The display implementation interface method is private, so it cannot be called through the object variables.
12. display the implementation interface. The implementation method of this interface can only be called through interface variables.
Eg:
{Name =}View Code