virtual methods and abstract classes

Summary of the characteristics of virtual methods

1. Add the virtual tag in front of the method that needs to be set as a virtual method in the parent class.

2. A virtual method must have an implementation in the parent class.

3. After the subclass inherits the parent class, it can choose to redo the virtual method, or choose not to redo it.

4. When overriding, access modifiers, return value types, parameters, etc. must be consistent.

5. When the method tag is virtual or override, it can be overridden.

Summary of the characteristics of abstract methods

1. Mark methods with the abstract keyword

2. Abstract methods cannot have any implementation in the parent class, and all abstract methods have no method body.

3. An abstract member must be in an abstract class.

4. An abstract class cannot be instantiated, and an object of an abstract class cannot be new.

5. An abstract class can have both abstract members and instance objects.

6. Abstract members cannot be private

7. Subclasses must recreate the abstract methods in the parent class, (because there is no default implementation in the parent class), unless the subclass is also marked as abstract

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325208159&siteId=291194637