Menu
Topics Index
...
`

Class with multiple constructors1991


If you need explanation Read this topic

If you need Answer Take test on this topic

Class with multiple constructors1991
What will be the output of the following program?
public class Confusing {
    public Confusing(Object o) {
        System.out.print("-Confusing Object-");
    }
    public Confusing(double[] d) {
        System.out.print("-Confusing Double-");
    }
    public static void main(String[] args) {
        new Confusing(null);
        new Confusing(null);
    }
}

A. -Confusing Object--Confusing Double-
B. -Confusing Double--Confusing Object-
C. -Confusing Object--Confusing Object-
D. -Confusing Double--Confusing Double-
E. Some other output
F. Compilation Error or Runtime Error
Topic: Advanced Java Programming Concepts

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

B

Posted by Dasharath Sandolla    2013-12-04 03:49:53


Ans is C.. null is taken as object not double type..

Posted by Sadanand Kalyankar Patil    2013-12-04 04:04:02


answer is 'D' because when we pass null as parameter then the constructor with double array object as formal parameter is invoked...

Posted by Sai Teja    2013-12-04 04:24:13


Answer is D......Since Object is the super-type of Double, the double version is more specific than the Object-version. So the second confusing method is called both the times...thus the result would be  "-Confusing Double--Confusing Double-"

Posted by Sneha Rapool    2013-12-04 06:17:54


ans is F ,we will get compilation error.....

Posted by Ankit Mudiraj    2013-12-04 13:32:29


Congratulations Sai Teja. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2013-12-05 03:31:28


© meritcampus 2019

All Rights Reserved.

Open In App