Differences between java Abstract classes and interfaces and java Abstract Interfaces

Source: Internet
Author: User

Differences between java Abstract classes and interfaces and java Abstract Interfaces
Zookeeper

Syntax:

1) abstract classes can provide implementation details of member methods, while interfaces can only have public abstract methods;

2) The member variables in the abstract class can be of various types, while the member variables in the interface can only be of the public static final type;

3) the interface cannot contain static code blocks and static methods, while the abstract class can have static code blocks and static methods;

4) A class can inherit only one abstract class, but a class can implement multiple interfaces.

Design Level:

Abstract is the relationship between inheritance and whether or not, and the interface implementation is the relationship between whether or not. It is better to say that there is an abstract class Door (Door) and a class inheritance subclass WoodDoor (wooden Door ), this is the inheritance of abstract classes. For example, there is a Bird class and an Airplane plane class. They all have a fly () method. There is no way to use abstract classes to solve this problem, the interface should be used, because it is clear that birds and planes are not sub-classes and parent classes. They only have a common behavior method. They both have the fly method. This is the concept of "whether.


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.