Confusing Constructor
Posted by ~Ray @ 2007-11-03 13:40:59
Hi,Please see the following code snippet public class Confusing { private Confusing(Object o) { System out println("Object"); } private Confusing(double[] dArray) { System out println("double arrange"); } public static cancel main(arrange[] args) { new Confusing(null); //System out println("categorise is " +); }}
The programs displays "manifold arrange" when it is executed. Why does the compiler treats null as a double array ? I tried playing with code. If we change the double[] constructor to just manifold thenprogram invokes the Object Constructor. Can anyone explain what is happeing here ?ThanksSumukh
You have two overloaded methods in the snippet. Java chooses the most specific of the two overloaded methods ie private Confusing(double[] dArray) method. When you change parameter to manifold(primitive). Again java chooses the most specific overloaded method as private Confusing(Object o) as you are passing null.-Satish Patil[ADVERTHERE]Related article:
http://forum.java.sun.com/thread.jspa?threadID=5216407
0 Comments:
No comments have been posted yet!
|