public class
TypePromotion {
|
void add(float a, float b) {
|
System.out.println(a + b + " float");
|
}
|
void add(long a, long b) {
|
System.out.println(a + b + " long");
|
}
|
public static void
main(String args[]) {
|
TypePromotion obj = new
TypePromotion();
|
obj.add(21, 21);
// integer value is passed
|
}
|
}
|
class
TypePromotion {
|
void add(float a, float b) {
|
System.out.println(a + b + " float");
|
}
|
void add(double a, double b) {
|
System.out.println(a + b + " double");
|
}
|
public static void
main(String args[]) {
|
TypePromotion obj = new
TypePromotion();
|
obj.add(21, 21);
// integer value is passed
|
}
|
}
|
public class
OverloadingExm {
|
void sum(int a, int b) {
|
System.out.println("int arg method invoked");
|
}
|
void sum(long a, long b) {
|
System.out.println("long arg method invoked");
|
}
|
public static void
main(String args[]) {
|
OverloadingExm obj = new
OverloadingExm ();
|
obj.sum(20, 20);// now int arg sum() method gets
invoked
|
}
|
}
|
class
TypePromotion {
|
void add(int a, long b) {
|
System.out.println(" 1st method invoked");
|
}
|
void add(long a, int b) {
|
System.out.println(" 2nd method invoked");
|
}
|
public static void
main(String args[]) {
|
TypePromotion obj = new
TypePromotion();
|
obj.add(21,
21);
|
}
|
}
|












