The seventh chapter in-depth understanding polymorphism 1. Richter Replacement principle:
In a software system, if a subclass appears where the parent class appears, and the entire software function has no effect, then we call it a Richter replacement.
The parent class variable points to the subclass Object!!
2.Is and AS
is to do type determination, in order to do the parent class object to the subclass type conversion, but also must use as
3. Two different ways to achieve polymorphism:
Ordinary class + virtual method
Abstract class + abstract method
All tutorials on the market clearly point to the idea that abstract classes cannot be instantiated.
4. Summary of Contents:
1, what are the ways to achieve object-oriented polymorphism?
There are 3 kinds, the first, the virtual method to achieve polymorphism, the second: the abstract method to achieve polymorphism of the third: interface to achieve polymorphism
So far, we have learned two kinds of:
The first kind: virtual method to realize polymorphism
The virtual method SayHello () is defined by using the virtual keyword in the normal class person, and then overridden by the override keyword in the subclass student for the parent class's SayHello () method.
The second kind: The abstract method realizes polymorphism
By defining the abstract Method fly () in the abstract class birds, and then rewriting the abstract Method fly () in the subclass "Swallow" to implement polymorphism, the override is the same as the virtual method, and the override keyword is used
2, can abstract classes be inherited?
Yes, it can be inherited not only by ordinary classes, but by abstract classes.
Depth. NET platform and C # programming note Seventh chapter in-depth understanding polymorphism