सीधे मुख्य सामग्री पर जाएं

#58 What is method overloading in Java | Compile Time Polymorphism | Method overloading क्या है?




package com.sudhirtheindian2.java123;

//class A{
// int sum(){
// int a =10, b=20,c;
// c=a+b;
// return c;
// }
//
// void sum(int x, int y){
//
// double c = x+y;
// System.out.println(c);
//
// }
// void sum(int x, double y){
// double c=x+y;
// System.out.println(c);
// }
//}
//public class compileT {
// public static void main(String[] args) {
//
// A an =new A();
// an.sum(100,10);
// an.sum(100,20.63);
// int sum= an.sum();
// System.out.println(sum);





// What is method overloading & compile time polymorphism in java

// whenever a class contain more than one method
// with same name and different types of parameter
// called method overloading

// syntax

// return type method_name(para1);
// return type method_name(para1, para2);




// }
//}























package com.sudhirtheindian2.java123;

class A{
int sum(){
int a =20,b=50,c;
c=a+b;
return c;
}
void sum(int x, int y){
double c=x+y;
System.out.println(c);

}
void sum(int x,double y){
double c=x+y;
System.out.println(c);


}

}
public class CompileTime {
public static void main(String[] args) {
A obj = new A();
int sum1 = obj.sum();
System.out.println(sum1);
obj.sum(100,50);
obj.sum(50,40.56);

}
}

टिप्पणियाँ

इस ब्लॉग से लोकप्रिय पोस्ट