Concept
Interface is an abstract type in the Java language, but the interface is not an abstract class, but an abstract method Collections and interfaces are usually declared as interface. A class inherits the abstract methods of the interface by inheriting the interface. The usage method is:
implement 接口名
Class describes the properties and methods of objects. It can be inherited. The inheritance method is:
extends 父类名
Difference
All properties of the interface are public static final.
All classes are public by default.
A subclass 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.
Recommended tutorial: Java tutorial
The above is the detailed content of The difference between interface and class in java. For more information, please follow other related articles on the PHP Chinese website!