Subscribe Us

Method Overriding in Java With Example

.
Method Overriding - Run Time Polymorphism

When a child class (sub class ) has the same method name as declared in parent class then those method are called as the override method . In overriding parent class method is called as " overridden method"
and child class method is called as the "overriding method ".

Example of method overriding 

class Teacher
{  
void exam()
{
System.out.println("Exam will on next monday");
}  
}  

class Student extends Teacher
{  
 void exam()
{
System.out.println("Chang the Exam schedule");
}  
public static void main(String args[])
{  
Student std = new Student();  
std.exam(); 
}  

}  
Output :
Change the exam schedule

Method Overriding Rules
There are some rules which must be follow while overriding .

  • Method signature (parameter list) of both parent and child class must be same .
  • Method name of both parent and child class must be same .
  • The return type of child method and parent method must be same as primitive level.
Hope !! The above Lesson of Method Overriding helpful for you ...

Thank You !
Sandeep Yadav

Tags : Overriding in java , method overriding example in java , rule of method overriding , method overriding in java 

Post a comment

0 Comments