java keyword-abstract

Abstract: not concrete, can not see clearly.

Abstract class representation. In the process of continuous extraction, the method declarations in the common content are extracted, but the methods are different and there is no extraction. At this time, the extracted methods are not specific and need to be marked with the specified keyword abstract and declared as abstract methods.

The class where the abstract method is located must be marked as an abstract class, that is, the class needs to be modified by the abstract keyword.

Features of abstract classes:

1: Abstract methods can only be defined in abstract classes. Abstract classes and abstract methods must be modified by the abstract keyword (classes and methods can be described, but variables cannot be described).

2: An abstract method only defines a method declaration, not a method implementation.

3: Abstract classes cannot be objects (instantiated).

4: The subclass can be instantiated only after inheriting the abstract class through subclasses and overriding all abstract methods in the abstract class. Otherwise, the subclass is also an abstract class.

Details of the abstract class:

1: Is there a constructor in an abstract class? Yes, used to initialize subclass objects.

2: Is it possible to define non-abstract methods in an abstract class? Can. In fact, there is not much difference between abstract classes and general classes. They are all describing things, but when abstract classes describe things, some functions are not specific. Therefore, both abstract classes and general classes need to define attributes and behaviors. However, there is one more abstract function than the general class. And there is one less object creation part than the general class.

3: What cannot coexist with the abstract keyword abstract? final , private , static

4: Can abstract methods not be defined in abstract classes? Can. The purpose of abstract methods is simply to prevent the class from creating objects.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325818206&siteId=291194637