In this tutorial, we will learn about Method Overriding in java. If we create a method in the child class with the same name as declared in parent class it is known as Method Overloading.
Page Contents
Rules to perform Method Overloading in Java:
- Method name should be same as declared in Parent class.
- Parameter of the method should be the same as a method declared in Parent class.
Example Program:
class Master{
public void show(){
System.out.println("This is show method in Master class");
}
public void show2(){
System.out.println("This is show2 method in Master class");
}
}
public class Student extends Master{
public void show(){
System.out.println("This is show method in Student class");
}
public static void main(String args[]){
Student obj=new Student();
obj.show();
obj.show2();
}
}
As in the above example, you can see the method show is already present in Master class but we are overriding this method in Student class. It means when we call this method with the help of object of Student class it will invoke the method which is defined inside the student class.
Method overriding is very helpful when we want to change the working of the method which is already defined in Parent class. In this case, with the help Method Overriding, we can Override that particular method in Child class.
Parvesh Sandila is a results-driven tech professional with 8+ years of experience in web and mobile development, leadership, and emerging technologies.
After completing his Master’s in Computer Applications (MCA), he began his journey as a programming mentor, guiding 100+ students and helping them build strong foundations in coding. In 2019, he founded Owlbuddy.com, a platform dedicated to providing free, high-quality programming tutorials for aspiring developers.
He then transitioned into a full-time programmer, where his hands-on expertise and problem-solving skills led him to grow into a Team Lead and Technical Project Manager, successfully delivering scalable web and mobile solutions. Today, he works with advanced technologies such as AI systems, RAG architectures, and modern digital solutions, while also collaborating through a strategic partnership with Technobae (UK) to build next-generation products.
