For example, suppose you have a car or bicycle method. All vehicles have the ability to "run". Even programmatically, all classes that inherit from the Vehicle class should have a run method. Therefore, normally, the run method should be defined in the Vehicle class and inherited, but since the driving method is different for each vehicle, the processing content cannot be defined in the Vehicle class.
To define a method whose processing is undecided, you can define a method called an abstract method by adding "abstract" to the beginning of the method. Do not write ** content processing ** in the abstract method. "Abstract" means "abstract". It is called an "abstract method" because it is an unfinished method for which no specific processing has been decided. An abstract method will result in an error if the subclass has not overridden the method. So you can force a subclass to override that method and define what it does. If you want your subclass to always have a method, define it as an abstract method in your superclass.
A class that has at least one abstract method is called an "abstract class" and is prefixed with "abstract". Abstract classes cannot instantiate. A class with an incomplete method called an abstract method is also incomplete. You cannot instantiate an unfinished class. [Example]
abstract class SuperClass { //Abstract class definition
abstract public void hello(); //Definition of abstract method
}
Recommended Posts