Abstract class and Interface Generally, it is not easy to differentiate. In my opinion, interfaces are more abstract than abstract classes. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
Abstract classes are used to list the behaviors required by a class, but they do not explicitly provide specific implementation methods for each behavior. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
When a class is derived from an abstract base class, the derived class inherits all the features of the base class. Override Use a specific version for keywords Replace Inherited
AbstractionMethod . 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
If the derived class does not provide specific implementation from all the abstract methods inherited from the abstract base class, the derived class is also an abstract class.0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
Implementing an interface is similar in concept to filling in the abstract method when an abstract class is expanded. The difference between the two is: 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
1. For interfaces, we only abstract behaviors. abstract classes often contain specific attributes and abstract behaviors and specific behaviors. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
To some extent, Interfaces are more abstract than abstract classes. Because the interface leaves more space for imagination (abstraction is to extract common and essential features from numerous things, and discard its non-essential features. For example, apple, bananas, raw pears, grapes, peaches, and so on. They share the same characteristics as fruits. The process of getting the concept of fruit is an abstract process. To be abstract, you must compare them. If there is no comparison, you cannot find the common part .)0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
2. When a non-abstract class is derived from an abstract class, the derived class uses the overwriting method to provide specific implementation of the abstract method. The method header must include the override keyword. When a class implements an interface, it must provide the specific implementation of all methods declared in the interface. Implementation classes do not overwrite them. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
3. abstract classes do not have to override all abstract methods of the base class. If one or more abstract methods are not covered, the derived class is also an abstract method. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
4. A class can only be derived from one base class, A class can implement multiple interfaces, and interfaces can be used as dataTypeReturn . 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
In terms of syntax, the difference between the two is: 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
1. abstract classes may declare data structures (attributes), while interfaces do not declare attribtute. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
2. Use keywords in abstract classes Abstract Declare the abstract method and add its accessibility. Instead of adding public or abstract keywords to the interface, use Int Erface. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
3. the abstract class may declare a specific method, but the interface does not declare a specific method. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
4. The base class inherits all attributes from the abstract class and can add its own attribute.The base class must provide its own attribute when implementing the interface, but the interface cannot. (For example, the inherited variables and abstract classes are provided, but interfaces cannot be provided) 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
5. The base class can override the abstract methods inherited from the abstract class, and the base class must all implement the interface methods without using the override keyword. 0 ï ± ¸. 2â æ (vwww.nfhot.com ° ª fiá] ª 8f
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.