Home  >  Article  >  Java  >  What is the connection between abstract classes and interfaces?

What is the connection between abstract classes and interfaces?

王林
王林forward
2020-08-03 16:37:392586browse

What is the connection between abstract classes and interfaces?

Contact:

(Recommended tutorial: java introductory tutorial)

1. Anyone can have abstract methods

2. Neither can directly create objects.

3. They all rely on the existence of subclasses to make sense. Subclasses must implement all their abstract methods.

4. All can implement multiple State

Difference:

Different members:

There is no constructor method in the interface, while abstract classes have constructor methods but cannot directly create objects.

Member methods in the interface are modified by public abstract by default, and only abstract methods can exist. There are both abstract methods and ordinary methods in abstract classes.

Member variables in the interface are decorated with static final by default, and only static constants are public. Variables in abstract classes do not have this restriction.

(Video tutorial recommendation: java video tutorial)

Different relationships:

The relationship between classes is inheritance: extends.

The relationship between interfaces is inheritance: extends.

The relationship between classes and interfaces is implementation: implements. Subclasses are called subimplementation classes.

The above is the detailed content of What is the connection between abstract classes and interfaces?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete