We have seen the class hierarchies -
Entertainment s example in Java Class Inheritance and IceCreamPrices example in Inheritance Example Program To Remove Duplicate Code. The class hierarchies look similar except that there is minor difference between them. IceCream is a concrete super-class where as Entertainment is an abstract super-class. The difference is explained below.
In reality
IceCream can exist, even with out FruitSaladWithIceCream , where as Entertainment can not exist on its own. It has to be either Movie , Drama or Circus or some other entertainment. Similarly Metal is an abstract class, since for we to show the Metal , we need to either show Gold or Iron or some thing else. If we had Mobile and MobileWithCamera , then Mobile would be a concrete class since it can exists on its own.
IceCream and Mobile are examples of concrete super-classes, where as Entertainment , Metal and Shape are examples of abstract super-classes.
In Java every class defined is by default concrete class, but if we want to implement abstract class, we need to use the abstract keyword before the class to mark a class as abstract class.
abstract class Shape Shape and a concrete class called Rectangle . Abstract class is prefixed with the keyword abstract , where as for concrete class we need not mention any keyword.
Shape shape1; // Can create a reference of abstract class
|