abstract method
A method modified with abstract has no method body, only a declaration. What is defined is a "specification" that tells subclasses that they must provide concrete implementations for abstract methods.
abstract class
A class that contains abstract methods is an abstract class. The specification is defined by the abstract method, and then subclasses are required to define the concrete implementation. Through abstract classes, we can strictly limit the design of subclasses and make them more common among subclasses.
The use of abstract classes
Classes with abstract methods can only be defined as abstract classes
An abstract class cannot be instantiated, that is, an abstract class cannot be instantiated with new.
Abstract classes can contain properties, methods, and constructors. But the constructor cannot be used to new instance, it can only be used to be called by subclasses.
Abstract classes can only be used to be inherited.
Abstract methods must be implemented by subclasses.
Separating method design from implementation
interface
An interface is an "abstract class" that is more "abstract" than an "abstract class", and can constrain subclasses in a more standardized manner. Only constants and abstract methods.
Interface definition
- Access modifier: can only be public or default.
- Interface name: Use the same naming scheme as class name.
- extends: Interfaces can inherit multiple times.
- Constants: Properties in interfaces can only be constants, always: public static final modification. Not even writing.
- Methods: Methods in an interface can only be: public abstract. If omitted, it is also public abstract