Please go through this simple program it should show " Number ... n"
but it is showing
"float a"at run time. I am using jdk 5.0
public class VarArg1 {
public void take()
{
System.out.println("no arg");
}
public void take(Number ... n)
{
System.out.println("Number ... n");
}
public void take(Double ... n)
{
System.out.println("Double ...n");
}
public void take(float a)
{
System.out.println("float a");
}
public void take(double a)
{
System.out.println("double a");
}
public static void main(String[] args) {
new VarArg1().take(2); // it Should show Number ... n but is is
showing float a
}
}
Abdul Mohsin
abdul82@gmail.com
Mark Thomas - 27 Sep 2006 19:31 GMT
> Please go through this simple program it should show " Number ... n"
> but it is showing
[quoted text clipped - 34 lines]
> Abdul Mohsin
> abdul82@gmail.com
The literal '2' is an int - there is no take(int), so it is upcast to a
float.
Double is a wrapper for double and although Java 5 allows for automatic
'boxing', but it won't happen here. Number is the abstract superclass
of Double.
Mark