|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
SCJP 5.0 Generics Mock Exam Questions - 4
3)What is the output of the following program
public class Gen<G>
{
G g;
Gen(G g)
{
this.g =g;
}
public static void main(String[] args)
{
Gen<String> arr[] = new Gen[5]; //line 1
arr[0] = new Gen("Java"); //line 2
arr[1] = new Gen(1); //line 3
arr[2] = (Gen<String>)new Gen(1); //line 4
arr[3] = (Gen<String>)new Gen<Integer>(1); //line 5
for(Gen o:arr)
{
System.out.println(o);
}
}
}
a)Compile time Error at line 1
b)Compile time Error at line 3
c)Compile time Error at line 4
d)Compile time Error at line 5
e)Run Time Error
Answer
3) d.
We can cast raw type to specific type but we cannot type cast Integer type to String type
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
|