Home > Java > JavaBase > body text

The difference between interface and class in java

王林
Release: 2019-11-15 15:26:41
Original
4591 people have browsed it

The difference between interface and class in java

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 接口名
Copy after login

Class describes the properties and methods of objects. It can be inherited. The inheritance method is:

extends 父类名
Copy after login

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!

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