Generics Wildcards2767 - Java Quiz Question


What will be the output of the following program?

public class BoundedWildCardDemo {

    public static void showXYZ(Coordinates<? extends ThreeD> c)
    {
        System.out.println("X Y Z Coordinates :");
                
        for(int i = 0; i < c.coords.length; i++)
        {
            System.out.println(c.coords[i].x+"    "+c.coords[i].y+"    "+c.coords[i].z);
        }
    }
    public static void main(String arg[])
    {
          
        ThreeD threeD[] ={
            new ThreeD(1,1, 1),new ThreeD(7, 9, 6), new ThreeD(18, 4, 1)
        };
        Coordinates<ThreeD> threeDCoord = new Coordinates<ThreeD>(threeD);
        showXYZ(threeDCoord);
    }
}
class TwoD
{
    int x, y;
        
    public TwoD(int x, int y) {
        this.x = x;
        this.y = y;
    }
}
class ThreeD extends TwoD
{
    int z;
    public ThreeD(int x, int y, int z) {
        super(x, y);
        this.z = z;
    }
}
class Coordinates<T extends TwoD>
{
    T[] coords;
    Coordinates(T[] coords)
    {
        this.coords = coords;
    }
}


A
X Y Z Coordinates :
1    1    1
1    1    1
1    1    1
B
X Y Z Coordinates :
C
X Y Z Coordinates :
1    1    1
7    9    6
18    4    1
D
Compilation Error
E
Runtime Error