Home  >  Article  >  Java  >  what is java abstract class

what is java abstract class

(*-*)浩
(*-*)浩Original
2019-11-09 13:22:056895browse

In the Java language, when the abstract keyword is used to modify a class, the class is called an abstract class. An abstract class is a collection of public attributes of all its subclasses and a class that contains one or more abstract methods.

what is java abstract class

Abstract class can be seen as a further abstraction of the class. In the object-oriented field, abstract classes are mainly used for type hiding. (Recommended learning: java course )

People often use the method of establishing abstract classes to provide a unified interface for a group of classes. The concept of abstract classes comes from real life. This allows us to think about the problem at a higher, more abstract level, thereby simplifying the complexity of the problem.

Use abstract classes in Java programs to implement abstract concepts in nature. The function of an abstract class is to organize many related classes together to provide a common class, and those concrete classes organized together are derived as its subclasses. An abstract class characterizes public behavior and transfers it to its derived classes through the inheritance mechanism.

An abstract class is a collection of public properties of all its subclasses, and is a class that contains one or more abstract methods. Abstract classes can be seen as further abstractions of classes.

First, objects in the software system can be abstracted from objects in the real world (main attributes and behaviors are retained, and secondary attributes and behaviors are removed), and then objects in the software system can be abstracted from objects in the software system. Class (removing attribute values, turning concrete objects into abstract concepts), while abstract classes are the abstract results of multiple classes. Abstract classes further describe the common characteristics and behaviors of multiple concrete classes.

From the perspective of system analysis, the use of abstract classes can better describe the abstract concepts of nature and more effectively complete the mapping between software systems and natural behavior systems. From the perspective of system design and implementation, the use of abstract classes can more effectively Make good use of these common attributes and operations to avoid duplication of code, thereby reducing the chance of errors and improving program development efficiency.

The implementation of Java abstract classes is explained through the keyword abstract. The format is:

[Modifies] abstract class ClassName {…}<br/>

Among them, Modifies is the modifier, abstract is the keyword to declare the abstract class, class is the keyword to define the class, ClassName is the class name, and the ellipsis in the curly brackets indicates the class. body part.

The member methods can be general member methods or abstract member methods. Abstract member methods are also described through the keyword abstract. In form, it only has the header part of the method, but no method body, not even a pair of braces used to describe the method body. This form is often called the prototype declaration of the method.

The format is as follows:

[Modifies] abstract returnType methodName(parameterLists);<br/>

The above is the detailed content of what is java abstract 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