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

How to define an interface in java

王林
Release: 2020-05-25 11:38:12
Original
2905 people have browsed it

How to define an interface in java

Definition of interface:

public interface  usb{}
Copy after login

Keyword interface;

Implement interface:

public class Computor implements  usb{}
Copy after login

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!

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