Interface: Initial understanding can be thought of as a special abstract class
When a method in an abstract class is abstract, the class can be represented by an interface.
Class is used to define classes
Interface for defining interfaces
When the interface is defined, the format features:
1, the constants in the interface are defined: constants, abstract methods.
2, the members in the interface have fixed modifier symbols
Constants: public static final
Method: Public Abstracts
Remember: The members in the interface are public
Interface: It is not necessary to create an object, because there is an abstract method.
Subclasses are required to implement a subclass that can be instantiated only after the abstract methods in the sub-class docking port have all been overwritten.
Otherwise, the subclass is an abstract class.
Interfaces can be implemented in many classes. It is also a form of conversion that is not supported for multiple inheritance. Java supports multiple implementations.
Features of the interface:
An interface is a rule that is exposed externally.
An interface is a function extension of a program.
Interfaces can be used to implement multiple implementations.
A class is an implementation relationship between interfaces, and a class can inherit a class and implement multiple interfaces at the same time.
There can be an inheritance relationship between an interface and an interface.
Interfaceinter{ Public Static Final intNUM = 3; Public Abstract voidshow ();}Interfaceintera{ Public Abstract voidmethod;}classdemo{ Public voidfunction () {}}classTestextendsDemoImplementsinter,intera{ Public voidShow () {} Public voidmethod () {}}Interfacea{voidMethodA ();}InterfaceBextendsa{voidMethodA ();}InterfaceCextendsb{voidMethodA ();}classDImplementsc{voidMethodA () {}voidMethodB () {}voidMethodA () {}}classInterfacedemo { Public Static voidMain (string[] args) {System.out.println ("Hello world!"); }}
/*class student{abstract void study (); void Sleep () {System.out.println ("Sleep")}//void Smoke ()//{//System.out.println ("Smokin G "); }}interface smokoing{void Smoke ();} Class Zhangsan extends sudent implements smoking{void Stude () {} public void Smoke () {}}class Lisi extends student{ }*/classsporter{voidplay ();}Interfacestudy{}classWangwuextendsSportsImplements {}class { Public Static voidMain (string[] args) {System.out.println ("Hello world!"); }}
Java Learning--interface interface