Since each different form of data in a composite hierarchy is represented by a distinct concrete class, we can write a separate method definition for each kind of data. Consider the following example. Now assume that x is a variable of type DeptDirectory . If we try to invoke the method firstAddress on x , Java will reject the code as erroneous because the class DeptDirectory does not contain a method named firstAddress . An abstract method is a method without a body.
Abstract methods can only appear in abstract classes.
Every concrete class extending a class containing abstract methods must provide concrete definitions for the abstract methods that override the missing bodies. This rule guarantees that abstract methods are never attached to objects. Each concrete class extending DeptDirectory must provide a definition for findAddress that includes a code body describing how it is implemented. The ordering of members within a class typically does not affect program behavior. Nevertheless, it is good programming practice to list class members in a consistent order.