Anda di halaman 1dari 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 - 4
public class Test1{
static void method(Object obj){
System.out.println("Object");
}
static void method(String str){
System.out.println("String");
}
Q1 public static void main(String args[]){
method(null);
}
}
What will be the output?

A1 String
A2 Object
A3 null
A4 Compiler Error

public class Test2{


static void method(StringBuffer obj){
System.out.println("StringBuffer");
}
static void method(String str){
System.out.println("String");
}
Q2 public static void main(String args[]){
method(null);
}
}
What will be the output?

A1 String
A2 Object
A3 null
A4 Compiler Error

class Test{}
public class Test3{
static void method(Object obj){
System.out.println("StringBuffer");
}
static void method(String str){
System.out.println("String");
}
static void method(Test t){
Q3 System.out.println("Test");
}
public static void main(String args[]){
method(null);
}
}
What will be the output?
A1 String
A2 Object
A3 Test
A4 Compiler Error

public class Test4{


public static void main(String args[]){
I i1 = new A();
I i2 = new B();
A a = new A();
System.out.println(i1 instanceof I);
System.out.println(i2 instanceof B);
Q4 System.out.println(a instanceof I);
}
}
interface I{}
class A implements I{}
class B implements I{}
What will be the output?
A1 true true true
A2 true false true
A3 true false false
A4 Compiler Error

public class Test5{


public static void main(String args[]){
System.out.println(I.k);
}
Q5 }
interface I{
int k;
}
What will be the output?
A1 true true true
A2 true false true
A3 true false false
A4 Compiler Error
public class Test6 implements I{
int k = 1;
public static void main(String args[]){
System.out.println(k);
}
Q6 }
interface I{
int k = 0;
}
What will be the output?
A1 0
A2 1
A3 null
A4 Compiler Error

public class Test7 implements I{


int k = 1;
static{
k = k * 2;
}
{
k = k * 2;
}
Q7 public static void main(String args[]){
Test7 t1 = new Test7();
Test7 t2 = new Test7();
System.out.println(t1.k);
System.out.println(t2.k);
System.out.println(k);
}
}
What will be the output?
A1 0
A2 1
A3 null
A4 Compiler Error

public class Test8{


static int k = 1;
static{
k = k * 2;
}
{
Q8 k = k * 2;
}
public static void main(String args[]){
System.out.println(k);
}
}
What will be the output?
A1 1
A2 2
A3 4
A4 Compiler Error

public class Test9{


static int k = 1;

{
k = k * 2;
}
Q9 public static void main(String args[]){
System.out.println(k);
}
}
What will be the output?

A1 1
A2 2
A3 4
A4 Compiler Error

public class Test10{


final static int k;
static{
k = 0;
}
Q10 public static void main(String args[]){
System.out.println(k);
}
}
What will be the output?
A1 0
A2 1
A3 null
A4 Compiler Error
Answers
1 String
2 Compiler Error
3 Compiler Error
4 true true true
5 true true true
6 Compiler Error
7 Compiler Error
8 2
9 1
10 0
JavaBeat 2005, India (www.javabeat.net)
Submit a Site - Directory - Submit Articles

Anda mungkin juga menyukai