Abstract classes and abstract methods
1 . By adding the abstract keyword in front of a class, this class becomes an abstract class .
(1) When a class becomes an abstract class, it cannot be used as an object , that is, a new object cannot be created, and cannot be initialized.
(2) Abstract method is only a method, cannot write method .
(3) When a class inherits an abstract class, it is necessary to rewrite The abstract method of the abstract class to implement the method.
(4) Abstract methods must be placed in the abstract class to be used, the abstract method is implemented in the abstract subclass, that is, the abstract subclass implementation of the abstract parent class all abstract methods.
(5) Abstract methods must be abstract classes, abstract classes, but not necessarily abstract methods.
(6) The abstract method of the parent class must be obtained by abstracting the sub-class to output the value of the method;
Conclusion: Abstract classes can only be used as parent classes.
2. Abstract methods
Note: Abstract methods cannot have implementation methods, followed by a semicolon directly after the function name; To implement an abstract method, you must have an abstract subclass to implement the method.
Define the method in the abstract class (parent Class):
Implemented in an abstract subclass:
3. Abstract attributes (encapsulation)
Second, the interface
Definition: The keyword interface is used to define an interface.
"Precautions"
1. A subclass can inherit multiple interfaces, resolving a subclass that inherits only one parent class's properties and methods.
2, in the interface, if the subclass inherits the method, it must implement this method.
Within an interface, you cannot define a property, a method, or a field.
Iii. Commission (delegate)
Understanding: A delegate can be seen as a container for a function that can refer to any function that satisfies its requirements.
Example: The delegate is equivalent to the screwdriver "base", to use what type of screwdriver (flat, plum, cross-type) is predetermined, as long as the conditions will be placed on the base.
Definition: A delegate can be considered a data type and can be used to define a variable, but he is a special type of data, and the variable that it defines can receive a value that can only be a function.
How to use the usage method:
Object-oriented basis (IV.)