Early binding and polymorphism
- The signature rules for C # function overloading are judged by the type and number of arguments, not by the name of the function.
- The function return value is not signed as an overload.
- Modifiers are not part of a signature, such as static
- In the same function, multiple parameter names are unique
- Ref, Out is a reference pass, the memory address of the parameter is passed
- Params as a parameter key, can only be used for the last parameter of a function
Inherited
- Cannot prevent subclasses from overriding the base-like signature method
- An inheritance relationship is a subclass of the same signature method that looks up first, then finds its base class
- The base keyword is used by C # to call base class functions, variables in subclasses
- The inheritance relationship is irreversible
- In addition to constructors and destructors, subclasses inherit some of the base class
- Custom classes inherit from the object type by default, but these types of C # cannot be inherited:,,,
System.ValueType
System.Enum
System.Delegate
System.Array
, etc.
- C # does not support inheriting from multiple classes
- C # does not support circular inheritance
- Sub-class objects can be assigned directly to the base class, whereas a strong turn is required
Virtual
- In C #, a subclass object can be assigned to a base class object, whereas a strong turn is required.
- The override keyword is used for subclasses overriding the same signature as the base class virtual function
- Use new and override to override the same signature function of the base class virtual
- A function of the virtual modifier that can only be executed at run time
- function is not modified by virtual, it can be determined at compile time whether it is called
Abstract classes and abstract methods
- Unable to instantiate with new
abstract 抽象类
abstract 抽象类可以有子类,其子类实现抽象方法后,可被new实例化对象
如声明了abstract 的函数,则必须声明abstract 的类
当override抽象基类,无法修改基类函数的签名
abstract函数,无法同时添加static、virtual关键字
abstract 类无法被声明为sealed、static类
OOP polymorphism and Inheritance essentials