Sun Certified Java Programmer(SCJP 1.

4)
JavaBeat Home SCJP 1.4 Home Objectives Forums Mock Exams Online Mock Exam Resources

Mock Exams MockQuestions MockQuestions MockQuestions MockQuestions MockQuestions 1 5 9 13 17 MockQuestions MockQuestions MockQuestions MockQuestions MockQuestions 2 6 10 14 18 MockQuestions MockQuestions MockQuestions MockQuestions MockQuestions 3 7 11 15 19 MockQuestions MockQuestions MockQuestions MockQuestions MockQuestions 4 8 12 16 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)); System.out.println(s); Q1 } } class Person{ Person(int i){} } What is the output? A1 A2 A3 A4 10 20 ClassCastException Compiler Error Compiler Error

import java.util.*; public class Test2{ public static void main(String a[]){ Map s = new Hashtable(); s.put(null,null); System.out.println(s); Q2 } } What is the output?

A1

[null = null]

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 } }

A1 A2 A3 A4

What is the output? [null = null] NullPointerException null [] import java.util.*; public class Test4{ public static void main(String a[]){ Map s = new LinkedHashMap(); s.put("1","one"); s.put("3","three"); s.put("2","two"); System.out.println(s); } } What is the output? [1=one,3=three,2=two] NullPointerException [1=one,2=two,3=three] []

Q4

A1 A2 A3 A4

import java.util.*; public class Test5{ public static void main(String a[]){ Map s = new HashMap(); s.put("1","one"); s.put("3","three"); Q5 s.put("2","two"); System.out.println(s); } } What is the output? A1 A2 A3 A4 [1=one,3=three,2=two] [3=three,2=two,1=one] cannot predict the order [] public class Test6{ public static void method(float f){ System.out.println("Float"); } public static void method(double f){ System.out.println("Double"); } public static void main(String a[]){

Q6 }

float f1 = 2.0f; float f2 = 2.0f; method(1.0); method(1.0f); method(1.0f*2.0f); method(1.0f*2.0); method(f1*f2); }

What is the output?

A1 A2 A3 A4

Double Double Double Double Double Float Float Float Float Float Double Float Float Double Float Double Float Float Double Double

public class Test7{ public static void method(byte b){ System.out.println("Byte"); } public static void method(int i){ System.out.println("Int"); } public static void main(String a[]){ byte b = 1; Q7 method(1); method(128); method((byte)128); method(b); } } What is the output? A1 A2 A3 A4 Byte Int Int Byte Byte Int Int Byte Byte Int Byte Byte Int Int Byte Byte

public class Test8{ public static void main(String a[]){ byte b = 1; char c = 2; short s = 3; int i = 4; Q8 c s i s } = = = = b; // 1 b; // 2 b; //3 c * b; //4

} Which of the following are correct? A1 A2 A3 A4 Error Error Error Error at at at at mark mark mark mark 1 2 3 4

public class Test9{ public static void main(String a[]){ final byte b = 1; char c = 2; short s = 3; int i = 4; c = b; // 1 Q9 s = b; // 2 i = b; //3 s = c * b; //4 } } Which of the following are correct?

A1 A2 A3 A4

Error Error Error Error

at at at at

mark mark mark mark

1 2 3 4

public class Test10{ public static void main(String a[]){ String s1 = "Sun"; String s2 = "Java"; s1.concat(s2); System.out.println(s1); Q10 } } What is output?

A1 A2 A3 A4

Sun Java SunJava JavaSun public class Test11{ public static void main(String a[]){ Integer i1 = new Integer(127); Integer i2 = new Integer(127); Long l = new Long(127);

System.out.println(i1 == i2); System.out.println(i1.equals(i2)); System.out.println(i1.equals(l)); } Q11 } What is output?

A1 A2 A3 A4

false true true true true true false true false Compiler Error

public class Test12{ public static void main(String a[]){ byte b = 100; Byte b1= new Byte(100); Byte b2 = new Byte(b); System.out.println(b1 == b2); System.out.println(b1.equals(b2)); Q12 } } What is output?

A1 A2 A3 A4

false true true false true true Compiler Error

public class Test13{ public static void method(String s){ System.out.println("String Version"); } public static void method(StringBuffer sb){ System.out.println("String Buffer Version"); } Q13 public static void main(String a[]){ method(null); } } What is output?

A1 A2 A3 A4

String Version String Buffer Version Runtime Exception 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"; String s = "Local"; Q14 method(s); System.out.println(s); System.out.println(t.s); } } What is output?

A1 A2 A3 A4

Local Instance Local New Instance Loca Add New Instance Compiler Error

public class Test15{ public static void method(StringBuffer sb){ sb.append(" Added"); sb = new StringBuffer("Hai"); } public static void main(String a[]){ StringBuffer sb = new StringBuffer("String Buffer"); Q15 method(sb); System.out.println(sb); } } What is output?

A1 A2 A3 A4

String Buffer String Buffer Added Hai Compiler Error

public class Test16{ public static void method(StringBuffer sb){ sb = new StringBuffer("Hai"); sb.append(" Added"); } public static void main(String a[]){ Q16 StringBuffer sb = new StringBuffer("String Buffer"); method(sb); System.out.println(sb); } }

What is output?

A1 A2 A3 A4

String Buffer String Buffer Added Hai 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 Q18 A1 A2 A3 A4 Q19 A1 A2 A3 A4 Q20 A1 A2 A3 A4 What is the default capacity of java.util.Hashtable? 10 16 11 20 What is the default capacity of java.util.HashMap? 10 16 11 20 Which of the following classes has synchronized methods? ArrayList Vector HashTable WeakHashMap

public class Test21{ public static void main(String a[]){ String s1 = new String("Hai"); Q21 String s2 = "Hai"; String s3 = new String("Hai").intern(); System.out.println(s1 == s2);

System.out.println(s1 == s3); System.out.println(s2 == s3); } } What is output? A1 A2 A3 A4 false false true true false true false false false false true true

public class Test22{ public static void main(String a[]){ String s1 = "SunMicroSystems"; System.out.println(s1.substring(0)); System.out.println(s1.substring(1,4)); System.out.println(s1.substring(8)); Q22 } } What is output?

A1 A2 A3 A4

SunMicrosystems sun oSystem SunMicrosystems unM Systems StringIndexOutOfBoundsException None Of the above

public class Test23{ public static void main(String a[]){ String s1 = "Sun"; System.out.println(s1.substring(5)); Q23 } } What is output? A1 A2 A3 A4 Q24 A1 A2 A3 A4 -1 0 StringIndexOutOfBoundsException ArrayIndexOutOfBoundsException Which of the following are static methods in java.lang.String class? valueOf length indexOf All the above. public class Test25{ public static void main(String a[]){ StringBuffer sb = new StringBuffer(8); sb.append("TestString"); System.out.println(sb.capacity());

System.out.println(sb.length()); } } Q25 What is output?

A1 A2 A3 A4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

8 10 10 10 18 10 18 18 Answers ClassCastException NullPointerException [null = null] [1=one,3=three,2=two] cannot predict the order. Double Float Float Double Float Int Int Byte Byte Error at mark 1 Error at mark 4 Error at mark 4 Sun false true false Compiler Error Compiler Error Local New Instance String Buffer Added String Buffer 0 11 16 Vector HashTable false false true SunMicrosystems unM Systems StringIndexOutOfBoundsException valueOf 18 10
JavaBeat 2005, India (www.javabeat.net) Submit a Site - Directory - Submit Articles

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.