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)); } }
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.
Just simple as in parameter u should mention the values as it mention in the method...Java will take the crt parameter and complie the value polymorphism
Class can have same name methods, only requirement is they should have different parameters, name and type is important!
Don't make it harder by your complicated words
@@bestlearn6131 that's not hard at all he just gave simple definition 😃
@@bestlearn6131 knowing the meaning of those words is necessary to understand what a method overloading really does...
@@bestlearn6131he just explained 6min video in two sentences
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));
}
}
doesnt work this way
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.
Best explanation sir
Easy to understand and concise!
Thank you so much sir😊
good explanation....👏
I think JavaScript handle's this issue quite interestingly with the help of rest parameter.
Great teaching skills
Sir class can be one type of function because in other language it's have same syntax somewhat
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?
Yes........!!
Your output will be XY.00
Thank you sir 😊❤
sir could you help how to give input into java like scanf in c
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");
int num = sc.nextInt();
I have a Question, Why are you using public keyword inside Calculator Class with various methods, i think its not needed sir .
Can you make a video on JavaDoc?
i know very out of subject thing
i kinda went back in nostalgia when he said got7 at 2:00
💚💚💚💚
Aghase spotted
Bhupendra jogi
No two methods with same name must have same parameter type and same number of parameters.
genuine
Kuss marwa rha h english accent dekh apna
nothing 🤣
sir in this video u took same method name "add" then how could the class demo can understand which one need to take
Just simple as in parameter u should mention the values as it mention in the method...Java will take the crt parameter and complie the value polymorphism