Menu
Topics Index
...
`

Generics Unbounded Wildcard2877


If you need explanation Read this topic

If you need Answer Take test on this topic

Generics Unbounded Wildcard2877
What will be the output of the following program?
public class GenericsWildCardDemo1 {
    public static void main(String args[])
    {
        Number[] ob =  {1.2, 2.2, 3.2, 4.2, 5.2};
        StoreNumbers<Double> obj = new StoreNumbers<Double>(ob);
        print(obj);
    }
    static void print(StoreNumbers<?> c)
    {
        for(int i = 0; i < c.obj.length; i++)
        {
            System.out.print(c.obj[i] + " ");
        }
    }
}

class StoreNumbers<T extends Number>
{
    T[] obj;
    StoreNumbers(T[] obj) {
        this.obj = obj;
    }
}

A. 1 2 3 4 5
B. 1.2 2.2 3.2 4.2 5.2
C. Compilation Error
D. Runtime Error
Topic: Generics Wildcards In Java With Examples

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.obj is the objct fr str numbr.print fnctn wil tk ob value n den prnt its values..this.obj refrs to currnt obj refrnc

Posted by Asma Mujtaba Khan    2014-08-19 08:38:51


Answer is C since Double[] cannot be converted to Number[] in the method call

Posted by Shashanka Mogaliraju    2014-08-19 10:09:32


c.compilation error..double data type cannot be converted to number[] wen method is called

Posted by Bilal Ahmad    2014-08-19 10:54:01


C

Posted by Rayapudi Ramya    2014-08-19 14:24:04


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

Posted by Merit Campus    2014-08-20 05:16:09


© meritcampus 2019

All Rights Reserved.

Open In App