The difference between a class, an abstract class, and an interface

Source: Internet
Author: User

Only single inheritance between classes and classes

There can be many implementations between the class and the interface;

Multiple inheritance between interface and interface;

  Statement Variable Method Relationships with interfaces Relationships with classes Whether the object can be constructed
Class Using the Class keyword declaration, the modifier is public Can be declared in any lawful manner Can be declared in any lawful manner Multi-Implementation Single inheritance objects can be constructed directly
Abstract class Using the abstract class keyword declaration, the modifier is public Can be declared in any lawful manner If an abstract class contains abstract methods, then the declaration of this method must be abstract. This method cannot access permissions to private, cannot use the final decoration method, cannot be decorated with static, and the abstract method has no method body. There can be no abstract method in an abstract class Multi-Implementation Single inheritance The object cannot be constructed directly, and if you want to construct it, you must inherit from the subclass and then construct
Interface Using the interface keyword declaration, the modifier is public The variables in the interface must be public static final, and this qualification is the default. The method declaration in the interface must be public abstract, which is the default.
The methods defined in the interface are all abstract methods.
Multiple inheritance Multi-Implementation Objects cannot be constructed directly, and if they are to be constructed, they must be implemented by subclasses and then constructed

The difference between a class, an abstract class, and an interface

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.