Home>Article>Java> The difference between java abstract class and interface

The difference between java abstract class and interface

王林
王林 Original
2019-11-09 17:45:37 2830browse

The difference between java abstract class and interface

The difference between interfaces and abstract classes:

1. Abstract classes can contain ordinary methods, but interfaces can only contain public and abstract methods (before JDK 1.8) ;

2. There are no access restrictions on member variables in abstract classes, but variables in interfaces can only be modified by public static final;

3. One interface can inherit multiple interfaces, But a class can only have one parent class, and a class can implement multiple interfaces;

4. An abstract class is an abstraction of a type of thing, and an interface is an abstraction of behavior. A class inheriting an abstract class represents the "is it" relationship, while a class implementing an interface represents the "is it having" relationship.

Recommended tutorial:java tutorial

The above is the detailed content of The difference between java abstract class and interface. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn