As discussed in Java Abstract Class, an abstract classes do not map to real life objects and they can not exist on their own, with out taking the form any of its concrete sub-classes. e.g.,
Shape can not exist on it own, it has to be either Rectangle or Square or Circle .
Abstract methods are those methods which have only the declaration but do not have a definition. Declaration means creating only the method signature (the method name, parameters and return type), but no method body, where as definition means creating the method signature and the method body as well.
For e.g., we know that every Shape has an area, but we do not know how to calculate the area, until we know what Shape it is. This is because the area calculation for Rectangle is different from the area calculation of Triangle , which is different from that of the Circle . So we will declare that we have a method called getArea() in Shape , but only define or implement the logic of calculating the area in there respective concrete sub-classes.
Calculate Areas CODE class CalculateAreas OUTPUT Area of rectangle is 21.0 DESCRIPTION Here we have created an abstract THINGS TO TRY
LINE A , the abstract method does not have any method body. The semicolon should be placed as soon as the method signature is complete.
Please read Rules For Abstract Methods and Abstract Classes for more details.
|