Differences between abstract classes and interfaces

Source: Internet
Author: User

Differences between abstract classes and interfaces

I recently reviewed some basic Java knowledge. Here I will summarize the differences between abstract classes and interfaces.

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. abstract class can have its own data members or non-abstarct member methods. In interface, only static data members that cannot be modified (that is, they must be static final, but data members are not defined in interfaces) are allowed. All member methods are abstract.

3. If a subclass implements an interface, all methods in the interface must be implemented (whether or not required); if it inherits an abstract class, you only need to implement the required methods.

4. abstract class is a base class and cannot be instantiated. interfaces are declarations. each class of the corresponding interface must implement methods.

 

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.