Java Function/Constructor Overloading Puzzle Last Updated : 03 Sep, 2018 Comments Improve Suggest changes Like Article Like Report Predict the output of the program Java public class GFG { private GFG(Object o) { System.out.println("Object"); } private GFG(double[] d) { System.out.println("double array"); } public static void main(String[] args) { new GFG(null); } } Solution: The parameter passed to the constructor is the null object reference and arrays are reference types too. If we try running the program, we get following. The program prints double array. We can notice that the compiler doesn't cause ambiguous call error. Java’s overload resolution process operates in two phases. The first phase selects all the methods or constructors that are accessible and applicable. The second phase selects the most specific of the methods or constructors selected in the first phase. One method or constructor is less specific than another if it can accept any parameters passed to the other. In our program, both constructors are accessible and applicable. The constructor GFG(Object) accepts any parameter passed to GFG(double[]), so GFG(Object) is less specific. (Every double array is an Object, but not every Object is a double array.) Create Quiz Comment S Shubham Juneja 0 Improve S Shubham Juneja 0 Improve Article Tags : Misc Java Java-Constructors java-puzzle Java-Overloading +1 More Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like