Home > Java > Javagetting Started > body text

What is the connection between abstract classes and interfaces?

王林
Release: 2020-08-03 16:37:39
forward
2553 people have browsed it

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!

Related labels:
source:csdn.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!