The purpose of writing code like this is to achieve polymorphism in
future.
If you have studied Mathematics, then there in Mathematics is a rule
i.e the part/whole of subset is also the part of superset, but not the
vice versa
same is the case here.
when you create a Parent Class (either abstract or not) or and
interface end extend one or more classes
from that interface/parent class then the parent class is considered
as superset and child classes are the
subsets of that superset.
It might be well explained by the following example (the java syntax)
public class animals
{
//some attributes and behaviors
//like having eyes, ears, eats/drinks stuff, moves around
protected void Eat();//Function to be overridden by each class that
extends this class.
}
------------------------------------------------------
public class bull extends animals
{
//having legs, eyes ears etc
public override void Eat()
{
//eats gross, drinks water etc
System.Out.Println("bull eats gross and drinks water");
}
}
---------------------------------------------------
public class Dog extends animals
{
//having legs, eyes ears etc
public override void Eat()
{
//eats meal, drinks water,milk etc
System.Out.Println("Dog Eats meal and drinks water/milk");
}
}
public class MainClass
{
public static void main(string [] args)
{
//i create the object of animals which can contain any of the two
animals i.e. bull and the dog.
animals a1=new bull();
a1.Eat();//this will call the bull class's eat function
a1=new dog();
a1.Eat();//this will call the dog class's eat function
//Note here the object is same but the reference to the object changes
at run time and
//output is different. This is so what called dynamic binding.
//this is the reason why mostly internet articles when using OOP
Concepts follow this
}
}
I think this might help you
please don't hesitate to write