Professional Documents
Culture Documents
4)
JavaBeat Home SCJP 1.4 Home Objectives Forums Mock Exams Online Mock Exam Resources
Mock Exams
MockQuestions - 1 MockQuestions - 2 MockQuestions - 3 MockQuestions - 4
MockQuestions - 5 MockQuestions - 6 MockQuestions - 7 MockQuestions - 8
MockQuestions - 9 MockQuestions - 10 MockQuestions - 11 MockQuestions - 12
MockQuestions - 13 MockQuestions - 14 MockQuestions - 15 MockQuestions - 16
MockQuestions - 17 MockQuestions - 18 MockQuestions - 19 MockQuestions - 20
Mock Exam - 2
import java.util.*;
public class Test1{
public static void main(String a[]){
Set s = new TreeSet();
s.add(new Person(20));
s.add(new Person(10));
Q1 System.out.println(s);
}
}
class Person{
Person(int i){}
}
What is the output?
A1 10 20
A2 ClassCastException
A3 Compiler Error
A4 Compiler Error
import java.util.*;
public class Test2{
public static void main(String a[]){
Map s = new Hashtable();
s.put(null,null);
Q2 System.out.println(s);
}
}
What is the output?
[null = null]
A1
A2 NullPointerException
A3 null
A4 []
import java.util.*;
public class Test3{
public static void main(String a[]){
Map s = new WeakHashMap(10);
s.put(null,null);
System.out.println(s);
}
Q3 }
import java.util.*;
public class Test4{
public static void main(String a[]){
Map s = new LinkedHashMap();
s.put("1","one");
Q4 s.put("3","three");
s.put("2","two");
System.out.println(s);
}
}
What is the output?
A1 [1=one,3=three,2=two]
A2 NullPointerException
A3 [1=one,2=two,3=three]
A4 []
import java.util.*;
public class Test5{
public static void main(String a[]){
Map s = new HashMap();
s.put("1","one");
Q5 s.put("3","three");
s.put("2","two");
System.out.println(s);
}
}
What is the output?
A1 [1=one,3=three,2=two]
A2 [3=three,2=two,1=one]
A3 cannot predict the order
A4 []
c = b; // 1
s = b; // 2
i = b; //3
s = c * b; //4
}
}
Which of the following are correct?
A1 Error at mark 1
A2 Error at mark 2
A3 Error at mark 3
A4 Error at mark 4
c = b; // 1
Q9 s = b; // 2
i = b; //3
s = c * b; //4
}
}
Which of the following are correct?
A1 Error at mark 1
A2 Error at mark 2
A3 Error at mark 3
A4 Error at mark 4
A1 Sun
A2 Java
A3 SunJava
A4 JavaSun
What is output?
A1 false true
A2 true false
A3 true true
A4 Compiler Error
A1 String Version
A2 String Buffer Version
A3 Runtime Exception
A4 Compiler Error
public class Test14{
static String s ="Instance";
public static void method(String s){
s+="Add";
}
public static void main(String a[]){
Test14 t = new Test14();
s = "New Instance";
Q14 String s = "Local";
method(s);
System.out.println(s);
System.out.println(t.s);
}
}
What is output?
A1 Local Instance
A2 Local New Instance
A3 Loca Add New Instance
A4 Compiler Error
A1 String Buffer
A2 String Buffer Added
A3 Hai
A4 Compiler Error
A1 String Buffer
A2 String Buffer Added
A3 Hai
A4 Compiler Error
import java.util.*;
public class Test17{
public static void main(String a[]){
Map m = new Hashtable(10,0.75f);
System.out.println(m.size());
Q17 }
}
What is output?
A1
A2 10
A3 7
A4 cOMPILER eRROR
A1 8 10
A2 10 10
A3 18 10
A4 18 18
Answers
1 ClassCastException
2 NullPointerException
3 [null = null]
4 [1=one,3=three,2=two]
5 cannot predict the order.
6 Double Float Float Double Float
7 Int Int Byte Byte
Error at mark 1
8
Error at mark 4
9 Error at mark 4
10 Sun
11 false true false
12 Compiler Error
13 Compiler Error
14 Local New Instance
15 String Buffer Added
16 String Buffer
17 0
18 11
19 16
Vector
20
HashTable
21 false false true
22 SunMicrosystems unM Systems
23 StringIndexOutOfBoundsException
24 valueOf
25 18 10
JavaBeat 2005, India (www.javabeat.net)
Submit a Site - Directory - Submit Articles