Write a program to show that during function overloading, if no matching argument is found, then Java will apply automatic type conversions (from lower to higher data type)
Write a program to show that during function overloading, if no matching argument is found, then Java will apply automatic type conversions (from lower to higher data type)
Program-01:
class Test
{
void method(int i)
{
System.out.println("Automatic Type Conversion to Integer:"+ i);
}
void method(double d)
{
System.out.println("Automatic Type Conversion to Double:"+ d);
}
void method(String s)
{
System.out.println("String Method Called:"+ s);
}
}
public class Auto_Type_Conversion
{
public static void main(String[] args)
{
Test s1 = new Test();
s1.method('a');
s1.method(2);
s1.method(2.0f);
s1.method("Sarthak Mund");
}
}
OutPut:
Automatic Type Conversion to Integer:97
Automatic Type Conversion to Integer:2
Automatic Type Conversion to Double:2.0
String Method Called:Sarthak Mund
Program-02:
class Test {
void FunOver(int i) {
System.out.println("Integer is :" + i);
}
void FunOver(float f) {
System.out.println("Float is :" + f);
}
void FunOver(double d) {
System.out.println("Double is :" + d);
}
}
public class FunOverload {
public static void main(String[] args) {
int i = 56;
float f = 56.3f;
double d = 55.632;
;
Test s1 = new Test();
s1.FunOver(i);
s1.FunOver(f);
s1.FunOver(d);
}
}
OutPut:
Integer is :56
Float is :56.3
Double is :55.632
Post a Comment