Differences between interfaces and abstract classes

Source: Internet
Author: User

Abstract class: A. classes that contain one or more abstract methods or semantics must be defined as abstract classes.
B. inherit all the abstract methods or
Attention. Otherwise, the derived class must also be an abstract class until it is fully realized.
C. abstraction must be public ).
D. There is no object entity in the abstract class, but the variable can be affirmed. In addition, the abstract class
There can be non-Abstract methods for derivative class.
Interface: 1. define abstract methods in the interface, indexing, and events
2. The interface must be implemented by a type. Therefore, it can only be declared as public by default.
Static
3. All methods, indexes, and events in the interface must be fully implemented.
4. One class can only bear one base class, but multiple interfaces can be implemented. The base class of the class must be placed at the most
First, and then the interface, which is separated by teasing.

 

1. interfaces can only contain methods and fields. abstract classes can contain methods or attributes and fields;
2. Methods in interfaces do not need to be implemented, but abstract classes can have implemented methods;
3. interfaces can replace multiple inheritance to some extent.
4. Implementing interfaces means that all methods in interfaces must be implemented. If you inherit the subclass or abstract class of an abstract class, you can only implement some methods.
5. interfaces and abstract classes are not converted into objects by instances.

 

 

I think the reason why many people are not clear about the image and interface may be that the interface is good or abstract.
I have talked a lot about it in the book, and many people have said it countless times. I think the main reason for using interfaces is that the project grows and more people are involved. There are three developers, three developers, and four developers, but to improve development efficiency, we need to do some basic work, such as some common Code methods and functions. So we put these methods and functions in the abstract class. As long as the subclass inherits the class, it will have the method. This basic class is the image class. However, programming also encounters another situation: the manager is Zhang San, the development system client, and Wang Wu, the development server. But how does the client access the server? This requires an Intermediate contract, which can be understood by both parties, communications are available as long as both parties comply. This is the interface.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.