Differences in Java abstract classes and interfaces

Source: Internet
Author: User

??

At the grammatical level:

1) Abstract classes can provide implementation details for member methods. Only the public abstract method can exist in the interface.

2) member variables in an abstract class can be of various types. The member variables in the interface can only be public static final types.

3) The interface cannot contain static code blocks and static methods. Abstract classes can have static code blocks and static methods;

4) A class can only inherit an abstract class. A class can implement multiple interfaces.

Add: The Abstart method can not be provided in an abstract class, nor can the same class be instantiated

At the design level:

Abstraction is the relationship that inheritance is "not". The interface implementation is a "no" relationship. Rather, there is an abstract class door (gate), a category of inheriting subclasses Wooddoor (wooden doors). This is the inheritance of abstract classes.

For example, there is a bird (bird) class. There is a (airplane) airplane class, they all have a method fly () method. There is no way to use abstract classes to solve the problem, to use the interface, because it is obvious that birds and airplanes are not sub-class and parent relationship, they just have a common behavior method, they all have the fly method, this is "there is no" concept.


Differences in Java abstract classes and interfaces

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.