Home>Article>Java> How to define an interface in java

How to define an interface in java

王林
王林 Original
2020-05-25 11:38:12 2806browse

How to define an interface in java

Definition of interface:

public interface usb{}

Keyword interface;

Implement interface:

public class Computor implements usb{}

Keyword to implement interface: implements ;

Example:

How to define an interface in java

(Video tutorial recommendation:java video)

The methods in the interface are Abstract method, so public abstract can be omitted. All variables are constants and must be assigned values. The default public abstract final int a=0;

How to define an interface in java

There can be multiple interfaces Inheritance, a class can implement multiple interfaces. The interface also has a function for decoupling. The interface is a special abstract class. All access modifiers between interfaces are public, and all methods are abstract methods. All variables are constants;

How to define an interface in java

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

Example:

How to define an interface in java

How to define an interface in java

How to define an interface in java

Recommended tutorial:Getting started with java development

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

Statement:
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