0% found this document useful (0 votes)
6 views3 pages

Over Loading & Overriding

Method overloading in Java enhances program readability by allowing multiple methods with the same name but different parameters within a class, while method overriding provides a specific implementation of a superclass method in a subclass. Overloading occurs within a single class, whereas overriding requires an inheritance relationship between two classes. Additionally, overloading is a compile-time polymorphism, and overriding is a run-time polymorphism, with strict parameter requirements differing between the two methods.

Uploaded by

shivanigundrathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Over Loading & Overriding

Method overloading in Java enhances program readability by allowing multiple methods with the same name but different parameters within a class, while method overriding provides a specific implementation of a superclass method in a subclass. Overloading occurs within a single class, whereas overriding requires an inheritance relationship between two classes. Additionally, overloading is a compile-time polymorphism, and overriding is a run-time polymorphism, with strict parameter requirements differing between the two methods.

Uploaded by

shivanigundrathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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 of the Method overriding is used to provide the
program. 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 different. In case of method overriding, parameter
must be same.

4) Method overloading is the example of compile time Method overriding is the example of run time
polymorphism. polymorphism.

5) In java, method overloading can't be performed by changing Return type must be same or covariant in
return type of the method only. Return type can be same or method overriding.
different in method overloading. But you must have to change
the parameter.
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...");
} }

You might also like