|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
SCJP 5.0 Generics Mock Exam Questions - 5
4) what is the output of compiling an running the following code?
import java.util.*;
class CheckTest {
public static void main(String [] args) {
Hashtable ht = new Hashtable<String, String>();
ht.put("chec", "check");
ht.put(1000, "check"); // line 1
ht.put("check", 20.01); // line 2
System.out.print(ht.get("chec") + " ");
System.out.print(ht.get(1000) + " "); //line 3
System.out.print(ht.get("check")); //line 4
}
}
a) Compilation fails due to error at line 1,2,3,4
b) Compilation fails due to error at line 3,4
c) Compiles fine and exception is thrown at runtime.
d) Compiles fine and prints "check check 20.01"
e) Compilation fails due to error at line 1,2
Answer
4)d
d is the correct answer because even Hashtable reference is created with Generic type the reference is stored in non-generic variable. So it act as an old collection.
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|