In this lecture we are discussing:
1) What is method overloading
a) what is necessary condition for method overloading?
b) example
2)what is constructor overloading ?
a)what is necessary condition?
b) example
#1
Method overloading:
:- In a same class we have more than or equal to two methods with same name
but with different parameters.
a)Necessary condition
i)at least two methods with same name in class.
ii)different parameters in methods might be of different data tyoe or nuumber of parameters are different
e.g add(int num1, int num2) , add(int num1, intnum2, int num3), add(float num1, float num2), add(int num1, float num2)
iii)return type might same or different does not matter
e.g public int add(int num1, int num2) public void add(int num1, int num2) is not overloaded because return type does not effect any change.
you got error when you want to do like this //Duplicate method add(int, int) in type
b)example
class Calc{
public void add(int num1,int num2){
}
public void add(float num1,float num2){
}
public void add(int num1, int num2 ,int num3){
}
public void add(int num1, float num2){
}
}
#2
Constructor overloading
:- I understand everyone understand constructor is a member method of a class
a)Necessary condition for constructor overloading
:- it just same as method overloading name must be same and parameters must be different .
e.g Calc(), Calc(int num) ,Calc(int num1, int num2)
b)example
class Calc{
int num1;
int num2;
Calc(){
//non -parametrized constructor
}
Calc(int num1){
this.num1=num1; //parametrized constructor with single parameters
}
Calc(int num1, int num2){
this.num1=num1;
this.num2=num2;
}
}
In this video we will see :
- Passing multiple parameter in method
- Creating multiple methods having same name
- Why we need method overloading
- Constructor overloading
- How overloading works
Github :- [ Ссылка ]
Instagram : [ Ссылка ]
Linkedin : [ Ссылка ]
Discord : [ Ссылка ]
More Learning :
Java - [ Ссылка ]
Python :- [ Ссылка ]
Django :- [ Ссылка ]
Spring Boot :- [ Ссылка ]
Spring Framework :- [ Ссылка ]
Servlet & JSP :- [ Ссылка ]
Hibernate Tutorial :- [ Ссылка ]
Rest API | Web Service Tutorial :- [ Ссылка ]
Git :- [ Ссылка ]
JavaScript :- [ Ссылка ]
Kotlin :- [ Ссылка ]
Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
[ Ссылка ]
Ещё видео!