0% found this document useful (0 votes)
2 views1 page

Method Overloading Notes

Method overloading allows multiple methods with the same name in a class, differentiated by their parameter lists, and is a form of compile-time polymorphism. Examples include methods with different parameter types, numbers, or orders. Key rules state that only the parameter list can change for overloading, while the return type cannot, and Java supports method overloading but not operator overloading, except for the + operator with Strings.

Uploaded by

raahimkhalid777
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)
2 views1 page

Method Overloading Notes

Method overloading allows multiple methods with the same name in a class, differentiated by their parameter lists, and is a form of compile-time polymorphism. Examples include methods with different parameter types, numbers, or orders. Key rules state that only the parameter list can change for overloading, while the return type cannot, and Java supports method overloading but not operator overloading, except for the + operator with Strings.

Uploaded by

raahimkhalid777
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

Method Overloading - Important Notes

Method Overloading means creating multiple methods with the same name in the same
class but with different parameter lists.
It is also known as compile-time polymorphism.

Examples:
1. add() with different parameter types:
int add(int a, int b)
double add(double a, double b)

2. add() with different number of parameters:


int add(int a, int b, int c)

3. print() with different order of parameters:


void print(int x, String s)
void print(String s, int x)

Rules:
- Only parameter list must change (type, number, or order).
- Return type alone cannot overload a method.
- Java supports method overloading but not operator overloading (except + for Strings).

You might also like