The interface is an abstract type in the Java language, but the interface is not an abstract class, but a collection of abstract methods. The interface is usually declared with interface. A class inherits the abstract method of the interface by inheriting the interface.
Usage method is: (Recommended learning: java course)
implement 接口名
Classes describe the properties and methods of objects.
can be inherited. The inheritance method is:
extends 父类名
Differences in syntax
–All interfaces Properties are all public static final;
– All classes are public by default;
Subclasses can only inherit one parent class (extends) and can inherit multiple interfaces (implement) .
Interface cannot be instantiated, but it can be implemented. A class that implements an interface must implement all methods described in the interface, otherwise it must be declared as an abstract class.
In Java, interface types can be used to declare a variable. They can become a null pointer, or be bound to an object implemented by this interface.
The above is the detailed content of The difference between java classes and interfaces. For more information, please follow other related articles on the PHP Chinese website!