You are on page 1of 5

Sun Certified Java Programmer(SCJP 1.

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


public class Test1 extends Base{
Test1(long i){}
public static void main(String args[]){}
}
Q1 class Base{
Base(int i){}
}
Which of the following constructors are if present in Base, will the program will compile
properly?
A1 Base(){}
A2 Base(long l){}
A3 Base(float f){}
A4 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 2
A2 4
A3 Compiler Error
A4 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 which of the following are valid constructors?


A1 Test4(){}
A2 void Test4(){}
A3 private Test4(){}
A4 All the above.

Q5 which of the following statements are true?


A1 constructors can be overriden.
A2 constructors can be overloaded
A3 constructors can return a value
A4 constructors can be static.

public class Test6{


Test6(int i, int j){
System.out.println("Int");
}
Test6(short i, short j){
System.out.println("Short");
}
Q6 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?
A1 Int
A2 Byte
A3 Short
A4 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?
A1 Byte Int Int
A2 Byte Byte Byte
A3 Byte Int Byte
A4 Int Int Int

public class Test8 extends Base{


Test8(){}
public static void main(String args[]){}
}
Q8 class Base{
Base() throws Exception{}
}
what is the output?
A1 Byte Int Int
A2 Byte Byte Byte
A3 Byte Int Byte
A4 Int Int Int

public class Test9 extends Base{


Test9()throws Exception{}
Test9(int i) {}
public static void main(String args[])throws Exception{
new Test9();
}
Q9 }
class Base{
Base() throws Exception{
System.out.println("Base");
}
}
what is the output?
A1 Base
A2 Compiler Error.
A3 Runtime exception
A4 none of the above

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?
A1 Base
A2 Compiler Error.
A3 Runtime exception
A4 none of the above

class Test11 extends B {


private Test11() { super(); }
public Test11(String msg) { this(); }
public Test11(int i) {}
}
class A {
11 public A() {}
public A(int i) { this(); }
}
class B extends A {
public boolean B(String msg) { return false; }
}
Select all valid answers:
A1 The code will fail to compile.
The constructor in A that takes an int as argument will never be called as a result of
A2
constructing an object of class B or Test11.
A3 class Test11 has three constructors.
At most one of the constructors of each class is called as a result of constructing an
A4
object of class Test11.

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 Base(){}
2 It will compile if we add super(2) in Test2().
private
3
public
Test4(){}
4
private Test4(){}
5 constructors can be overloaded.
6 Int
7 Byte Byte Int
8 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

You might also like