Abstract MethodsIn Chapter 7, we introduced abstract classes as a way to define the framework for a collection of related classes. Among other things, an abstract class can declare abstract methods. An abstract method is designated by the abstract keyword in the method declaration. Abstract methods can only be defined in abstract classes. An abstract method declaration consists of the method name , return type, parameter list, throws clause (if any), and a semicolon. There are no braces and no method body. Abstract methods are used to impose a certain structure on subclasses of an abstract class. The abstract method provides the basic method syntax to which subclasses must adhere . Nonabstract subclasses must provide an implementation of any abstract methods defined in superclasses. How the methods are implemented is up to the subclass. The only restriction is that the method name, return type, and input parameter list must match the abstract method declaration. Example: Abstract MethodsTo see abstract methods in action, look at the example in the "Abstract Classes" section of Chapter 7 where the Shape class defines two abstract methods intended to compute the area and circumference of a 2-D geometric shape. |