Home >Java >javaTutorial >[java object-oriented] Describe the interface in detail

[java object-oriented] Describe the interface in detail

(*-*)浩
(*-*)浩forward
2019-09-10 16:51:582626browse

The concept of interface

[java object-oriented] Describe the interface in detail

##Interface reflects the scalability of things. To give a specific example, we know that cats cannot jump high, but when the Cat class implements the Jumping interface, the cat can jump high. In other words, the thing "cat" expands the function of "high jump".

Use of interface

Define an interface class-Jumping

[java object-oriented] Describe the interface in detail

The implementation class Cat implements the Jumping interface

[java object-oriented] Describe the interface in detail Test class.

[java object-oriented] Describe the interface in detailLook at the left side for compilation and the right side for execution, so the execution result is:

[java object-oriented] Describe the interface in detail

Interface and class

1. Between classes

Classes and classes can be connected through inheritance (extends), but inheritance can only be single inheritance.

2. Interfaces and interfaces

Interfaces and interfaces can also be connected through inheritance (extends), but inheritance in interfaces can be multiple inheritance.

3. Between classes and interfaces

The connection between classes and interfaces can be through implementations, or there can be multiple implementations, just separate them with commas.

Note: It is worth mentioning that if a subclass wants to inherit the parent class and implement the interface, it is also possible. The usage format is:


public class Cat extends Animal implements Jumpping,Dancin

The above is the detailed content of [java object-oriented] Describe the interface in detail. 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
Previous article:What does @Autowired do?Next article:What does @Autowired do?