Method Overriding
Method Overriding
- Refer to this code sample.
class Monkey {
void eat (){
// Eat with hands
}
void climb(){
// Climb with the help of body
}
}
class Man extends Monkey{
void eat (){
// Eat with spoons, forks in a plate
}
void climb(){
// Use a ladder to climb
}
}
- Acording to the above code you can see that Monkey & Man are not equal.
- changing method body of a method receiving from the super class to the sub class is known as Method Overriding (Method body is the code inside a method).
Refer to this code sample.
class Father(){
String car;
}
class Son extends Father{
}


Comments
Post a Comment