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

Q1

A1 A2 A3 A4

Mock Exam - Constructor public class Test1 extends Base{ Test1(long i){} public static void main(String args[]){} } class Base{ Base(int i){} } Which of the following constructors are if present in Base, will the program will compile properly? Base(){} Base(long l){} Base(float f){} It will compile properly.

public class Test2 extends Base{ Test2(long i){ super(2); } Test2(){} public static void main(String args[]){ new Test2(2); } } class Base{ Q2 Base(int i){ System.out.println(i); } Base(byte i){ System.out.println(i*2); } } what will be the output?

A1 A2 A3 A4

2 4 Compiler Error It will compile if we add super(2) in Test2().

Q3 which of the following keywords can be applied to constructors? A1 private

A2 public A3 void A4 All the above Q4 A1 A2 A3 A4 Q5 A1 A2 A3 A4 which of the following are valid constructors? Test4(){} void Test4(){} private Test4(){} All the above. which of the constructors constructors constructors constructors following statements are true? can be overriden. can be overloaded can return a value can be static.

Q6

A1 A2 A3 A4

public class Test6{ Test6(int i, int j){ System.out.println("Int"); } Test6(short i, short j){ System.out.println("Short"); } Test6(byte i, byte j){ System.out.println("Byte"); } public static void main(String args[]){ Test6 t = new Test6(1,2); } } which of the following statements are true? Int Byte Short Compiler error

public class Test7{ Test7(int i, int j){ System.out.println("Int"); } Test7(short i, short j){ System.out.println("Short"); } Q7 Test7(byte i, byte j){ System.out.println("Byte"); } public static void main(String args[]){ byte b1 = 1; byte b2 = 2; Test7 t1 = new Test7(b1,b1);

Test7 t2 = new Test7(b1*1,b1*2); Test7 t3 = new Test7(b1*b1,b1*b2); } } what will be the output? Byte Int Int Byte Byte Byte Byte Int Byte Int Int Int public class Test8 extends Base{ Test8(){} public static void main(String args[]){} } class Base{ Base() throws Exception{} } what is the output? Byte Int Int Byte Byte Byte Byte Int Byte Int Int Int public class Test9 extends Base{ Test9()throws Exception{} Test9(int i) {} public static void main(String args[])throws Exception{ new Test9(); } } class Base{ Base() throws Exception{ System.out.println("Base"); } } what is the output? Base Compiler Error. Runtime exception none of the above

A1 A2 A3 A4

Q8

A1 A2 A3 A4

Q9

A1 A2 A3 A4

public class Test10 extends Base{ Test10(){} Test10(int i) {} public static void main(String args[]){ new Test10(); Q10 } } class Base{ Base() { System.out.println("Base");

} Base(int i) throws Exception{ System.out.println("No argument constructor."); } } what is the output? Base Compiler Error. Runtime exception none of the above class Test11 extends B { private Test11() { super(); } public Test11(String msg) { this(); } public Test11(int i) {} } class A { public A() {} public A(int i) { this(); } } class B extends A { public boolean B(String msg) { return false; } } Select all valid answers: The code will fail to compile. The constructor in A that takes an int as argument will never be called as a result of constructing an object of class B or Test11. class Test11 has three constructors. At most one of the constructors of each class is called as a result of constructing an object of class Test11.

A1 A2 A3 A4

11

A1 A2 A3 A4

12 Which of the following statements are true? A1 The default constructor has a return type of void A2 The default constructor takes a sungle parameter. A3 The default constructor takes no parameters A4 The default constructor is not created if the class has anyconstructors of its own. Answers 1 2 3 4 5 6 7 8 Base(){} It will compile if we add super(2) in Test2(). private public Test4(){} private Test4(){} constructors can be overloaded. Int Byte Byte Int Byte Byte Int

9 Compiler Error. 10 Base B) The constructor in A that takes an int as argument will never be called as a result of constructing an object of 11 class B or Test11. C)class Test11 has three constructors. 3) The default constructor takes no parameters 12 4) The default constructor is not created if the class has any constructors of its own.
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.