Predict the output of the program
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.)
This article is contributed by Shubham Juneja. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Overloading in Java
- Constructor Overloading in Java
- Different ways of Method Overloading in Java
- Output of Java program | Set 22 (Overloading)
- GFact 48 | Overloading main() in Java
- Method overloading and null error in Java
- Method Overloading and Ambiguity in Varargs in Java
- Method Overloading with Autoboxing and Widening in Java
- Difference between Method Overloading and Method Overriding in Java
- A Java Random and StringBuffer Puzzle
- Java Ternary Operator Puzzle
- Java Multicasting (Typecasting multiple times) Puzzle
- Function overloading and return type
- Overloading of Thread class run() method
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.LinkedList.offer(), offerFirst(), offerLast() in Java
- Java.lang.Short toString() method in Java with Examples
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java