Home >Java >JavaBase >What is the difference between abstract class and interface in java

What is the difference between abstract class and interface in java

王林
王林Original
2020-04-27 13:19:199701browse

What is the difference between abstract class and interface in java

The differences are as follows:

Abstract class:

1. Abstract classes are modified with abstract;

2. Abstract classes cannot be instantiated. , that is, the new keyword cannot be used to instantiate an object;

3. Classes containing abstract methods (methods modified with the abstract keyword) are abstract classes and must be modified with the abstract keyword;

4. An abstract class may or may not contain abstract methods. An abstract class may have specific methods;

5. An abstract method in an abstract class only has a method body and no specific implementation;

(Recommended video tutorial: java video)

Interface:

1. The interface is modified with interface;

2. The interface cannot Be instantiated;

3. A class can implement multiple interfaces;

4. The methods in the interface are abstract methods;

5. The interface cannot contain instances Or static methods (static methods must be implemented, methods in interfaces are abstract methods and cannot be implemented).

Recommended tutorial: java entry program

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