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

The difference between java classes and interfaces

(*-*)浩
Release: 2019-11-11 11:08:59
Original
3663 people have browsed it

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

Classes describe the properties and methods of objects.

can be inherited. The inheritance method is:

extends 父类名
Copy after login

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!

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