Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
144 views

Difference Between Method Overloading and Method Overriding in Java - Javatpoint

The document compares method overloading and method overriding in Java. Method overloading involves changing the parameters within a class for compile-time polymorphism. Method overriding involves implementing a superclass method differently in a subclass for run-time polymorphism, where the parameter types must be the same but the return type can be the same or covariant. Examples of each are provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

Difference Between Method Overloading and Method Overriding in Java - Javatpoint

The document compares method overloading and method overriding in Java. Method overloading involves changing the parameters within a class for compile-time polymorphism. Method overriding involves implementing a superclass method differently in a subclass for run-time polymorphism, where the parameter types must be the same but the return type can be the same or covariant. Examples of each are provided.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

6/15/2021 Difference between Method Overloading and Method Overriding in java - javatpoint

Difference between method overloading and method


overriding in java
There are many differences between method overloading and method overriding in java. A list of
differences between method overloading and method overriding are given below:

No. Method Overloading Method Overriding

1) Method overloading is used to increase the readability Method overriding is used to


of the program. provide the specific
implementation of the method
that is already provided by its
super class.

2) Method overloading is performed within class. Method overriding occurs in two


classes that have IS-A
(inheritance) relationship.

3) In case of method overloading, parameter must be In case of method overriding,


different. parameter must be same.

4) Method overloading is the example of compile time Method overriding is the


polymorphism. example of run time
polymorphism.

5) In java, method overloading can't be performed by Return type must be same or


changing return type of the method only. Return type covariant in method overriding.
can be same or different in method overloading. But
you must have to change the parameter.

⇧ SCROLL TO TOP

https://www.javatpoint.com/method-overloading-vs-method-overriding-in-java 2/6
6/15/2021 Difference between Method Overloading and Method Overriding in java - javatpoint

Java Method Overloading example

class OverloadingExample{  
static int add(int a,int b){return a+b;}  
static int add(int a,int b,int c){return a+b+c;}  
}  

Java Method Overriding example

class Animal{  
void eat(){System.out.println("eating...");}  
}  
class Dog extends Animal{  
void eat(){System.out.println("eating bread...");}  
}  

← Prev
Next →


For Videos Join Our Youtube Channel: Join Now

Feedback

Send your Feedback to feedback@javatpoint.com

Help Others, Please Share

⇧ SCROLL TO TOP

https://www.javatpoint.com/method-overloading-vs-method-overriding-in-java 3/6

You might also like