My dear friends today my aim is to tell you about the an important OPP concept.That is method OVERRIDING.
Method overriding has following properties,
1. Overriding and rided both methords has same method signature.Even the parameters/arguments are same.
2. But the implementation is diiferent.
See the below example..
class Animal{
public void getName(){
System.out.println("I am an animal");
}
}
class Lion extends Animal{
public void getName(){
System.out.println("I am a Lion");
}
public static void main(String args[]){
Animal a=new Animal();//The different is how we implement.
a.getName();
Lion l=new Lion();//The different is how we implement.
l.getName();
}
}
Now you will obtain the below result.
Method overriding has following properties,
1. Overriding and rided both methords has same method signature.Even the parameters/arguments are same.
2. But the implementation is diiferent.
See the below example..
class Animal{
public void getName(){
System.out.println("I am an animal");
}
}
class Lion extends Animal{
public void getName(){
System.out.println("I am a Lion");
}
public static void main(String args[]){
Animal a=new Animal();//The different is how we implement.
a.getName();
Lion l=new Lion();//The different is how we implement.
l.getName();
}
}
Now you will obtain the below result.
That is all....try to understand it... :)