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

[java object-oriented] Describe the interface in detail

(*-*)浩
Release: 2019-09-10 17:40:53
forward
2662 people have browsed it

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
Copy after login

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!

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