Menu
Question Index
...

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<Number> obj = new StoreNumbers<Number>(ob);
        print(obj);
    }
    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;
    }
}


1 2 3 4 5
1.2 2.2 3.2 4.2 5.2
Compilation Error
Runtime Error

Doubts

Problems

Topic: Generics Wildcards In Java With Examples

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App