Understanding abstract classes
In Chapter 9, we covered the abstract
keyword. Let’s review some key points that we discussed. An abstract
method is exactly that – it is abstract. It has no code. It doesn’t even have curly braces – {}
. This is typically a design decision. The class containing the abstract
method wants subclasses to provide the code. This means that the class itself is “incomplete” and therefore any class defining an abstract
method must itself be abstract
. Any subclass of the abstract
class must either override the abstract
method or declare that it too is abstract
. The compiler will complain otherwise.
However, the inverse is not the case – an abstract
class need not have any abstract
methods at all. Again, this is a design decision. Since the class is marked as abstract
, it is considered “incomplete” (even though it may contain code for all the methods). This prevents objects based on abstract
classes...