Hi,
Create abstract class when
1> When you are not sure about what the abstract method of that class will do when the class will get inherited.
2> When you want to define different feature of the abstract method to different class inheriting it.
For e.g look at this real life e.g
You want to purchase a car(abstract class) under certain parameters like Color of car and engine of car(abstract methods) and for that You have created your mindset that if i purchase HondaCar(Runtime Class)then your car should have Blue Color and cctvi engine. But if i Purcahse GmCar(RunTime Class) then it should have Red color and advanced cctvi engine but at the biginning you are not sure whether you wiil buy a HondaCar or GmCar. in this case abstract class is created because you have certain common methods but about you are not sure about the content of that method.
Hope you understand
abstract class ChColorEngine
{
abstract public void carColor();
abstract public void engine();
}
class HondaCar extends ChColorEngine
{
public void carColor()
{
System.out.println("This car should have Blue color");
}
public void engine()
{
System.out.println("This car should have cctvi engine");
System.out.println("");
}
}
class GmCar extends ChColorEngine
{
public void carColor()
{
System.out.println("This car should have Red color");
}
public void engine()
{
System.out.println("This car should have advanced cctvi engine");
}
}
class MainCar
{
public static void main(
String args[])
{
HondaCar H=new HondaCar();
H.carColor();
H.engine();
GmCar G=new GmCar();
G.carColor();
G.engine();
}
}