Traditional Culture Encyclopedia - The 24 Solar Terms - Three forms of polymorphic realization
Three forms of polymorphic realization
1. The virtual method can give an implementation to the method in the parent class, and the virtual method must have an implementation part, even if it is empty. Some points to note about virtual methods: If there is a method in the parent class that needs to be rewritten by subclasses, it can be marked as virtual; Virtual methods must be implemented in the parent class, even if they are empty; Subclasses of virtual methods can be overridden or not.
2. Abstract classes are polymorphic. Generally speaking, classes that only talk and do not do can't be instantiated. First of all, abstract classes cannot be instantiated, and abstract classes can have ordinary members.
The significance of the existence of abstract classes: abstract classes cannot be instantiated, but can only be inherited by other classes. A subclass of an abstract class must override (implement) all abstract members in the abstract class (unless the subclass is also an abstract class). ) Abstract classes are designed to rewrite polymorphism (code reuse). An abstract class can have instance members and abstract members.
3. Interface is a specification. You can write common code by agreeing to follow a certain specification. A set of methods with various functions are defined. Law can be understood as an interface. Anyone who wants to live in China must abide by the laws of China, which means that anyone who wants to live in China must be aware of the legal interface.
Members in the interface cannot be implemented, members in the interface cannot have access modifiers, and implicitly exposed interfaces can have properties, methods, indexers, etc. But they can't have fields, and all programs in the interface must be fully implemented in subclasses.
- Previous article:What season is the Millennium? What should I pay attention to?
- Next article:The story of Tomb-Sweeping Day in Grade One.
- Related articles
- How to make the health care effect better before and after the heavy snow solar terms?
- How is the water temperature of the car getting higher and higher?
- Wheat copywriting short sentences are clean and cured
- What are the specialties in Shanxi?
- How to quickly relieve chest tightness and shortness of breath?
- How about planting seven or eight centimeters of jujube trees now?
- How to disinfect the room, it is best to be simple and effective.
- How to remember solar terms in geography?
- Solar term wisdom
- Is it cold in Shanghai for the New Year?