Home>Article>Java> The difference between java classes and interfaces

The difference between java classes and interfaces

(*-*)浩
(*-*)浩 Original
2019-11-11 11:08:59 3459browse

The difference between java classes and interfaces

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!

Statement:
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
Previous article:what is java inheritance Next article:what is java inheritance