The differences between abstract classes and interfaces in Java

Source: Internet
Author: User

1, abstract class represents a kind of is-a relationship, the interface is often expressed as a function. A class can only use one inheritance relationship at a time. But a class can implement multiple interfaces.

2, the abstract class has its own data members, you can also have their own non-abstract method, the interface can only have static data members can not be modified (that is, must be static final, but in interface generally do not define data members), all the member methods are abstract.

3, the implementation of the abstract class and interface class must implement all his methods, abstract classes can have non-abstract methods, interfaces can not be implemented by methods.

4, the method in the interface is the public abstract type by default.

5, the variables in the abstract class are friendly by default,

6, the variables in the interface are public static final, and must be assigned the initial value, the implementation class can not be redefined, and can not be re-assigned.

The differences between abstract classes and interfaces 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.