Explaining the abstract and final keywords
As we know, when coding methods, we can apply the access modifier keywords, namely private, protected, public, and package-private (no keyword). Two other keywords have special significance regarding inheritance: abstract and final. Both are opposites of each other, which is why both cannot be applied to a method at the same time. Let’s discuss them now, starting with abstract.
The abstract keyword
The abstract keyword is applied to classes and methods. While abstract classes will be discussed more fully in Chapter 10, we will be discussing them here also (for reasons that will soon become obvious). An abstract method has no implementation (code). In other words, the method signature, rather than following it with curly braces, {}, which represents the implementation, an abstract method signature is simply followed by a semi-colon. Marking a method as abstract implies the following:
- The class must be
abstractalso
...