SlideShare a Scribd company logo
J AV A
TE CHN OLOG IE S
Centurion University Of Technology And
Management
N ame: - Hitesh kumar N ath
Regd.N O.: -
200301150005
B arnc h: - E E E
POLYMORPHISM
TAB LE OF CON TE N TS
D efinition
01
Types of
Polymorphism
02
Compile Time
03
04
E xamples
05 06
Run Time Advantages
D efinition
Polymorphism is the concept of one entity providing multiple
implementations or behavior's and It is the ability of an object to make
more that one form.
Types Of Polymorphism
Polymorphism
Compile Time
Polymorphism
Run Time
polymorphism
Compile Time polymorphism : -
 Compile-time polymorphism is also known as static polymorphism or early
binding.
 Compile-time polymorphism is a polymorphism that is resolved during the
compilation process. Overloading of methods is called through the reference
variable of a class. Compile-time polymorphism is achieved by method
overloading and operator overloading.
Method Overloading : -
 A class having multiple methods having same name
but different in parameters, it is known as Method
Overloading
 Method overloading increases the readability of the program.
 There are two ways to overload the method in java
1. By changing number of arguments
2. By changing the data type
Syntax For Method Overloading : -
package com.company; // by changing num of
arguments
public class add {
static int add(int a,int b){return a+b;}
static int add(int a,int b,int c){return a+b+c;}
}
class TestOverloading{
public static void main(String[] args){
System.out.println(add.add(15,16));
System.out.println(add.add(15,16,17));
}
}
 Here we have created two
methods for adding two and
three numbers respectively.
 Used the Static methods.
Output: -
Run Time polymorphism : -
 Runtime polymorphism is a process in which a call to an overridden
method is resolved at runtime rather than compile-time.
 An overridden method is called through the reference variable of a
superclass. The determination of the method to be called is based
on the object being referred to by the reference variable.
 Upcasting: - If the reference variable of Parent class refers to the
object of Child class, it is known as upcasting.
Method Overriding: -
 If Child class has the same method as declared in the parent
class, it is known as method overriding in Java.
 Method overriding is used to provide the specific
implementation of a method which is already provided by its
superclass. And used for Run time polymorphism.
Syntax for Method Overriding: -
package com.company;
public class Vehicle {
void run(){System.out.println("Vehicle is running");
}
}
class Bike2 extends Vehicle{
void run(){System.out.println("Bike is running safely");
}
public static void main(String args[]){
Bike2 obj = new Bike2();
obj.run();
}
}
Output :-
Advantages
Code
Cleanliness
Reusability
and
Extensibility
Aligned with
real world
THAN K
YOU !

More Related Content

Similar to JAVA_POLYMORPHISM.pptx

Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.net
suraj pandey
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Arif Ansari
 
Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2
ssuserd2d58b
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
thamaraiselvangts441
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
RiturajJain8
 
Method overloading
Method overloadingMethod overloading
Method overloading
Azaz Maverick
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
JavaTportal
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالالبرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكال
Mahmoud Alfarra
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
Java2Blog
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
kiran Patel
 
Method overloading
Method overloadingMethod overloading
Method overloading
VaibhavSingh531
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
harsh kothari
 
Chapter4__Method_Lim Lyheng_RULE (2).pdf
Chapter4__Method_Lim Lyheng_RULE (2).pdfChapter4__Method_Lim Lyheng_RULE (2).pdf
Chapter4__Method_Lim Lyheng_RULE (2).pdf
MornThea
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
Kavitha713564
 
P.7 media 2 polymorphism
P.7 media 2 polymorphismP.7 media 2 polymorphism
P.7 media 2 polymorphism
ahmadmuzaqqi
 
Core java oop
Core java oopCore java oop
Core java oop
Parth Shah
 
Polymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh SarkarPolymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh Sarkar
Animesh Sarkar
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
Suraj Bora
 
JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
SofiaArquero2
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptx
RobertCarreonBula
 

Similar to JAVA_POLYMORPHISM.pptx (20)

Overloading and overriding in vb.net
Overloading and overriding in vb.netOverloading and overriding in vb.net
Overloading and overriding in vb.net
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2Www javatpoint-com-corejava-interview-questions-2
Www javatpoint-com-corejava-interview-questions-2
 
polymorphism method overloading and overriding .pptx
polymorphism method overloading  and overriding .pptxpolymorphism method overloading  and overriding .pptx
polymorphism method overloading and overriding .pptx
 
Polymorphism.pptx
Polymorphism.pptxPolymorphism.pptx
Polymorphism.pptx
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالالبرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكال
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
C++ concept of Polymorphism
C++ concept of  PolymorphismC++ concept of  Polymorphism
C++ concept of Polymorphism
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Java(Polymorphism)
Java(Polymorphism)Java(Polymorphism)
Java(Polymorphism)
 
Chapter4__Method_Lim Lyheng_RULE (2).pdf
Chapter4__Method_Lim Lyheng_RULE (2).pdfChapter4__Method_Lim Lyheng_RULE (2).pdf
Chapter4__Method_Lim Lyheng_RULE (2).pdf
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
P.7 media 2 polymorphism
P.7 media 2 polymorphismP.7 media 2 polymorphism
P.7 media 2 polymorphism
 
Core java oop
Core java oopCore java oop
Core java oop
 
Polymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh SarkarPolymorphism in Java by Animesh Sarkar
Polymorphism in Java by Animesh Sarkar
 
Polymorphism and its types
Polymorphism and its typesPolymorphism and its types
Polymorphism and its types
 
JAVA LOOP.pptx
JAVA LOOP.pptxJAVA LOOP.pptx
JAVA LOOP.pptx
 
javaloop understanding what is java.pptx
javaloop understanding what is java.pptxjavaloop understanding what is java.pptx
javaloop understanding what is java.pptx
 

More from Hitesh Kumar Nath

TCP_IP.pptx
TCP_IP.pptxTCP_IP.pptx
TCP_IP.pptx
Hitesh Kumar Nath
 
Weather monitoring System Using STM32
Weather monitoring System Using STM32Weather monitoring System Using STM32
Weather monitoring System Using STM32
Hitesh Kumar Nath
 
PSOC-Swing Equation.pptx
PSOC-Swing Equation.pptxPSOC-Swing Equation.pptx
PSOC-Swing Equation.pptx
Hitesh Kumar Nath
 
Analysis Of Tesla Model Y.pptx
Analysis Of Tesla Model Y.pptxAnalysis Of Tesla Model Y.pptx
Analysis Of Tesla Model Y.pptx
Hitesh Kumar Nath
 
Optics ppt (attenuation and Fiber materials ).pptx
Optics ppt (attenuation and Fiber materials ).pptxOptics ppt (attenuation and Fiber materials ).pptx
Optics ppt (attenuation and Fiber materials ).pptx
Hitesh Kumar Nath
 
Buck Converter.pptx
Buck Converter.pptxBuck Converter.pptx
Buck Converter.pptx
Hitesh Kumar Nath
 
Distance Protection and Distance Realy.pptx
Distance Protection and Distance Realy.pptxDistance Protection and Distance Realy.pptx
Distance Protection and Distance Realy.pptx
Hitesh Kumar Nath
 

More from Hitesh Kumar Nath (7)

TCP_IP.pptx
TCP_IP.pptxTCP_IP.pptx
TCP_IP.pptx
 
Weather monitoring System Using STM32
Weather monitoring System Using STM32Weather monitoring System Using STM32
Weather monitoring System Using STM32
 
PSOC-Swing Equation.pptx
PSOC-Swing Equation.pptxPSOC-Swing Equation.pptx
PSOC-Swing Equation.pptx
 
Analysis Of Tesla Model Y.pptx
Analysis Of Tesla Model Y.pptxAnalysis Of Tesla Model Y.pptx
Analysis Of Tesla Model Y.pptx
 
Optics ppt (attenuation and Fiber materials ).pptx
Optics ppt (attenuation and Fiber materials ).pptxOptics ppt (attenuation and Fiber materials ).pptx
Optics ppt (attenuation and Fiber materials ).pptx
 
Buck Converter.pptx
Buck Converter.pptxBuck Converter.pptx
Buck Converter.pptx
 
Distance Protection and Distance Realy.pptx
Distance Protection and Distance Realy.pptxDistance Protection and Distance Realy.pptx
Distance Protection and Distance Realy.pptx
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 

JAVA_POLYMORPHISM.pptx

  • 1. J AV A TE CHN OLOG IE S Centurion University Of Technology And Management
  • 2. N ame: - Hitesh kumar N ath Regd.N O.: - 200301150005 B arnc h: - E E E POLYMORPHISM
  • 3. TAB LE OF CON TE N TS D efinition 01 Types of Polymorphism 02 Compile Time 03 04 E xamples 05 06 Run Time Advantages
  • 4. D efinition Polymorphism is the concept of one entity providing multiple implementations or behavior's and It is the ability of an object to make more that one form.
  • 5. Types Of Polymorphism Polymorphism Compile Time Polymorphism Run Time polymorphism
  • 6. Compile Time polymorphism : -  Compile-time polymorphism is also known as static polymorphism or early binding.  Compile-time polymorphism is a polymorphism that is resolved during the compilation process. Overloading of methods is called through the reference variable of a class. Compile-time polymorphism is achieved by method overloading and operator overloading. Method Overloading : -  A class having multiple methods having same name but different in parameters, it is known as Method Overloading  Method overloading increases the readability of the program.  There are two ways to overload the method in java 1. By changing number of arguments 2. By changing the data type
  • 7. Syntax For Method Overloading : - package com.company; // by changing num of arguments public class add { static int add(int a,int b){return a+b;} static int add(int a,int b,int c){return a+b+c;} } class TestOverloading{ public static void main(String[] args){ System.out.println(add.add(15,16)); System.out.println(add.add(15,16,17)); } }  Here we have created two methods for adding two and three numbers respectively.  Used the Static methods. Output: -
  • 8. Run Time polymorphism : -  Runtime polymorphism is a process in which a call to an overridden method is resolved at runtime rather than compile-time.  An overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.  Upcasting: - If the reference variable of Parent class refers to the object of Child class, it is known as upcasting. Method Overriding: -  If Child class has the same method as declared in the parent class, it is known as method overriding in Java.  Method overriding is used to provide the specific implementation of a method which is already provided by its superclass. And used for Run time polymorphism.
  • 9. Syntax for Method Overriding: - package com.company; public class Vehicle { void run(){System.out.println("Vehicle is running"); } } class Bike2 extends Vehicle{ void run(){System.out.println("Bike is running safely"); } public static void main(String args[]){ Bike2 obj = new Bike2(); obj.run(); } } Output :-