Home  >  Article  >  Java  >  What is the difference between java interface and class?

What is the difference between java interface and class?

青灯夜游
青灯夜游Original
2019-12-26 13:26:155162browse

Java is an object-oriented programming language. It not only absorbs the various advantages of the C language, but also abandons the difficult-to-understand concepts such as multiple inheritance and pointers in C. Therefore, the Java language has two characteristics: powerful functions and simple and easy to use. . As a representative of static object-oriented programming languages, Java language perfectly implements object-oriented theory and allows programmers to perform complex programming with an elegant way of thinking.

What is the difference between java interface and class?

Java has the characteristics of simplicity, object-oriented, distributed, robustness, security, platform independence and portability, multi-threading, and dynamics [2] . Java can write desktop applications, Web applications, distributed systems and embedded system applications, etc.

Interface (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 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 父类名

Syntax difference

– All properties of the interface are 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.

Recommended learning: Java video tutorial

The above is the detailed content of What is the difference between java interface and class?. 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