Created
June 29, 2021 03:58
-
-
Save Ram-1234/894cc8ab34573dfd7bd222db453cdd74 to your computer and use it in GitHub Desktop.
Method Overriding in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1-If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java. | |
2-In other words, If a subclass provides the specific implementation of the method that has been declared by one of its parent class, | |
it is known as method overriding. | |
//Java Program to illustrate the use of Java Method Overriding | |
//Creating a parent class. | |
class Vehicle{ | |
//defining a method | |
void run(){System.out.println("Vehicle is running");} | |
} | |
//Creating a child class | |
class Bike2 extends Vehicle{ | |
//defining the same method as in the parent class | |
void run(){System.out.println("Bike is running safely");} | |
public static void main(String args[]){ | |
Bike2 obj = new Bike2();//creating object | |
obj.run();//calling method | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment