Java Abstract class: 2008.10.29
- Abstract classes are classes that cannot be converted into objects.
- When a class is declared as an abstract class, you must add the modifier Abstract
- An abstract class can contain anything that a general class can contain.
- Abstract classes can also contain abstract methods. This method can only be declared and not implemented (conventional classes cannot contain abstract methods)
- If an abstract class does not have any abstract methods, it is more appropriate to use interfaces.
- Abstract classes are used for inheritance. They exist for the following reasons:
- Abstract classes are high-level summaries of classes.
- Abstract classes can include the public attributes and public behaviors shared by all their subclasses.
- When an instance is generated, the user is forced to generate more specific instances to ensure code security.
Abstract Method
- Abstract methods are added with abstract keywords during method declaration.
- Abstract methods are declared and not implemented.
- Only abstract classes can have abstract methods.
- If a subclass of an abstract class is not an abstract class, it must overwrite all abstract methods in the parent class.