Differences between interfaces and abstract classes in Java

Source: Internet
Author: User

Often see such a problem, is to ask the difference between the two, I also summed up:

1, Macro said, one is a class, one is an interface, the class supports only single inheritance, the interface supports multiple inheritance

2, on the microscopic level, is from the inside.

A, member variable aspect

    • Interfaces can contain methods, properties, constants (unchanged, but do not want to always take from the database the amount of wasted resources)
    • An abstract class can include any member of an interface, and it needs to satisfy the methods that can be implemented internally and those that are not implemented, and must have methods that are not implemented.

B, the interface class is public, and the abstract class may not be public

c, generally used, the interface is at the top, and then the abstract class implements the interface, and then the object class implements the abstract class

D, implementing an interface is a must to implement all the virtual methods, but the abstract class is not

Same point

are not directly instantiated

Differences between interfaces and abstract classes in Java

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.