Engineering Full Stack Apps with Java and JavaScript
Predict the result:
public class NullOverloadCheck { static void myMethod(Float o) { System.out.println("Float"); } static void myMethod(Integer i){ System.out.println("Integer"); } public static void main(String[] args) { myMethod(null); } }
Compilation will fail with message like: The method myMethod(Float) is ambiguous for the type NullOverloadCheck.
null is a valid value for the types Float and Integer; and both of the types are not related through inheritance. So Java will not be able to select one and hence it will fail at compile time.
Logged in users see lesser ads and get more features.
If you want to solve the questions together with the experts and understand the concepts better, please contact us using the contact form or WhatsApp numbers. Selected people get to do that without any additional charges.