Differences between abstract classes and interfaces in Java

Source: Internet
Author: User
1. abstract class represents an inheritance relationship in Java. A class can only use an inheritance relationship once. However, a class can implement multiple interfaces.

2. In abstract class
You can have your own data members or non-Abstarct member methods. In the interface, you can only have static data members that cannot be modified (that is, they must be
Static final, but data members are generally not defined in the interface). All member methods are abstract.

3. abstract class and interface have different design concepts. Abstract class represents the "is-a" relation, and interface represents the "like-a" relation.

4. classes that implement abstract classes and interfaces must implement all the methods in them. Abstract classes can have non-abstract methods. There is no implementation method in the interface.

5. the variables defined in the interface are of the public static final type by default and must be given the initial values. Therefore, the Implementation class cannot be redefined or changed.

6. the variables in the abstract class are friendly by default. Their values can be redefined in the subclass or assigned again.

7. The methods in the interface are public and abstract by default.

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.