#25 Method Overloading in Java

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO10 (10% Discount)

Coupon: TELUSKO20 (20% Discount)

For More Queries WhatsApp or Call on : +919008963671

Udemy Courses:

In this lecture we will learn:
- Parameters of a method
- Method overloading in Java
- When does method overloading happen?
- Different ways of method overloading in Java

#1
It is not compulsory that a class should have methods and variables. It will be empty also.
- The parameters that except the values in a method should be equal to the parameters that we pass in a method to call it.
- As it might create a problem if the parameters excepted by the method are not equal to the number of values passed.
- So, to overcome this problem we do overloading.
- As we can have two methods we the same name but different parameters.
- Either the number of parameters or the type of parameters should be different.
- Method with the same name and parameters but with different return types will also not work. The return type does not matter here. Method name and parameters matter only.

#2
Method overloading:- In Java, there can be more than one method with the same name but the number of parameters or type of parameters should be different.

- Method overloading is also known as Compile-time Polymorphism, Static Polymorphism, or Early binding in Java.
- In Method overloading compared to parent argument, child argument will get the highest priority.

#3
Different ways of Method Overloading in Java:-
1. Changing the number of parameters
- Method overloading can be achieved by changing the number of parameters while passing to different methods.

2. Changing Data Types of the Arguments
- If methods have the same name but have different parameter types then also methods are considered as overloaded.

3. Changing the Order of the Parameters of Methods
- By rearranging the parameters of two or more overloaded methods.

More Learning :

Donation:
PayPal Id : navinreddy20
Рекомендации по теме
Комментарии
Автор

Class can have same name methods, only requirement is they should have different parameters, name and type is important!

yitingchen
Автор

Sir class can be one type of function because in other language it's have same syntax somewhat

rahulbarot
Автор

When we return double value, the variable in main class to which the value will be assigned should also be of the type double, right?

agilan
Автор

I think JavaScript handle's this issue quite interestingly with the help of rest parameter.

rudra
Автор

I feel Java is unable to satisfy user requirements here.. I may return a value I may not return a value with same type and number of arguments. But Java doesn't support that.

vinaykumarbandarapalli
Автор

sir could you help how to give input into java like scanf in c

AmalManoj-mz
Автор

class Calculator {
int add(int... numbers) {
int sum = 0;
for (int num : numbers) {
sum += num;
}
return sum;
}
}

public class Main {
public static void main(String[] args) {
Calculator calc = new Calculator();

System.out.println(calc.add(5, 6));
System.out.println(calc.add(5, 6, 7));
System.out.println(calc.add(5, 6, 7, 8));
}
}

shazirnazir
Автор

No two methods with same name must have same parameter type and same number of parameters.

darshilchitranshi
Автор

i know very out of subject thing
i kinda went back in nostalgia when he said got7 at 2:00

💚💚💚💚

vedantsargara
Автор

Kuss marwa rha h english accent dekh apna

paragonmarketingagency
Автор

sir in this video u took same method name "add" then how could the class demo can understand which one need to take

GOLLAPALLIAKKULAPPAGARIHRUTHIK