OVERLOADING IN JAVA
2 type of overloading
1. method overriding
Providing multiple implemention of any method inside the same class is called as overloading.
2. constructor overloading
Providing multiple implemention of any constructor inside the same class is called as constructor overloading.
NOTE
example
// overloaded methhod
class sum
{
int a;
int b;
sum()
{
}
sum(int a,int b)
{
this.a=a;
this.b=b;
}
public void add(int a,int b)
{
System.out.println("sum of "+a+" and "+b+" : "+(a+b));
}
// overloaded methhod
public void add(float a,float b)
{
System.out.println("sum of "+a+" and "+b+" : "+(a+b));
}
// overloaded methhod
public void add(int a,int b,int c)
{
System.out.println("sum of "+a+" ,c "+ +" and "+c+" : "+(a+b+c));
}
}
2 type of overloading
1. method overriding
Providing multiple implemention of any method inside the same class is called as overloading.
2. constructor overloading
Providing multiple implemention of any constructor inside the same class is called as constructor overloading.
NOTE
- overloading can be performed by only change the number of argu,data type and number of order
- method overloading is implementing polymorphysm in java.
example
// overloaded methhod
class sum
{
int a;
int b;
sum()
{
}
sum(int a,int b)
{
this.a=a;
this.b=b;
}
public void add(int a,int b)
{
System.out.println("sum of "+a+" and "+b+" : "+(a+b));
}
// overloaded methhod
public void add(float a,float b)
{
System.out.println("sum of "+a+" and "+b+" : "+(a+b));
}
// overloaded methhod
public void add(int a,int b,int c)
{
System.out.println("sum of "+a+" ,c "+ +" and "+c+" : "+(a+b+c));
}
}
Comments
Post a Comment