Home > Java > JavaBase > How to understand abstract classes in java

How to understand abstract classes in java

王林
Release: 2019-11-12 09:38:17
Original
2920 people have browsed it

How to understand abstract classes in java

What is an abstract class?

The method modified by abstract is called an abstract method; the class modified by abstract is called an abstract class.

An abstract class cannot be instantiated because it is not a concrete class, or such a class is not complete enough and cannot directly use the new keyword to call its constructor to generate an object of this class. We can use abstract to define an abstract class and abstract method.

Abstract class instance:

abstract class 类名
{
abstract int 方法名(int x,int y);
}
Copy after login

Abstract methods have no method body. It should be noted that abstract classes can have both abstract methods and ordinary methods. Note that abstract methods do not have method bodies (that is, there are no curly braces after the methods). All entity subclasses that inherit this abstract class must implement this abstract method.

Characteristics of abstract classes:

(1) Abstract classes cannot be instantiated

(2) Constructors and static methods cannot be abstract

(3) Abstract methods of parent classes are often implemented in subclasses

(4) Abstract classes can have object references pointing to subclass objects

Recommended tutorials:java tutorial

The above is the detailed content of How to understand abstract classes 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