Home > Java > JavaBase > How to define interface in java

How to define interface in java

王林
Release: 2019-11-13 14:59:38
Original
3387 people have browsed it

How to define interface in java

1. Definition of interface:

public interface usb{}

Keyword interface;

Implementation interface: public class Computor implements usb{}

Keywords for implementing the interface: implements;

How to define interface in java

2. The methods in the interface are all abstract methods, so public abstract can be omitted If not written, all variables are constants and must be assigned values. The default is public abstract final int a=0;

How to define interface in java

3. Interfaces can have multiple inheritances and can be implemented in one class Those multiple interfaces, the interface also has a function for decoupling. The interface is a special abstract class. All access modifiers between interfaces are public, all methods are abstract methods, and all variables are constants. ;

How to define interface in java

4. A class implements an interface and must implement all methods in the interface;

How to define interface in java

Recommended tutorial :JavaTutorial

The above is the detailed content of How to define interface in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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