Create a Java program to demonstrate method overloading with method ambiguity and resolution using casting
In the provided Java code, there's a potential ambiguity issue because of the way the arguments are passed to the print method. When you pass a floating-point number, like 38.12, Java can interpret it either as a double or as an int.
class AmbiguityExample { void print(int num) { System.out.println("Integer : " + num); } void print(double num) { System.out.println("Double : " + num); } public static void main(String[] args) { AmbiguityExample obj = new AmbiguityExample(); obj.print((int) 42.9); obj.print(38.12); } }
Integer : 42 Double : 38.12
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions