Online Test - SCJP Sample Test #1

This is a sample test of Sun Certified Java Programmer(SCJP). There are ten questions and score 90 is the grade to pass the test.

1. What is the result of attempting to compile and run the program below?

Class C {

public static void main(String[] args) {

int[]a1[]=new int[3][3]; //3

int a2[4]={3,4,5,6}; //4

int a2[5]; //5

}}

A. Compiletime error at lines 3,4,5
B. Compiltime error at line 4,5
C. Compiletime error at line 3
D. Runtime Exception
E. None of the above

2. Which lines generate compile time errors?

interface I{

void f1(); // 1

public void f2(); // 2

protected void f3(); // 3

private void f4(); // 4

}

A. Compiletime error at lines 1,2,3,4
B. Compiletime error at line 3
C. Compiletime error at line 1
D. Compiletime error at lines 3,4
E. None of the above

3. Which statement is correct one according class c?

class C{

int i;

public static void main (String[] args) {

int i; //1

private int a = 1; //2

protected int b = 1; //3

public int c = 1; //4

System.out.println(a+b+c); //5

}}

A. Compiletime error at lines 1,2,3,4,5
B. Compiletime error at lines 2,3,4,5
C. Compiletime error at lines 2,3,4
D. Prints 3
E. None of the above

4. class C {

public static void main (String[] a1) {

System.out.print(a1[1] + a1[2] + a1[3]);

}}

What is the result of attempting to compile and run the program?

A. Prints: ABC
B. Prints BC and Runtime Exception
C. Prints: BCD
D. Runtime Exception
E. None of the above

5. class C{

static int s;

public static void main(String a[]){

C obj=new C();

obj.m1();

System.out.println(s);

}

void m1();

{

int x=1;

m2(x);

System.out.println(x+"");

}

void m2(int x){

x=x*2;

s=x;

}}

A. Prints 1,2
B. Prints 2,0
C. Prints 2,2
D. Compile time error
E. None of the above

6. class C {

public static void main(String[] args) {

int i1=1;

switch(i1){

case 1:

System.out.println("one");

case 2:

System.out.println("two");

case 3:

System.out.println("three");

}}}

What is the result of attempting to compile and run the program?

A. Prints one two three
B. Prints one
C. Compile time error
D. Runtime exceptionf

7. Each element must be unique

Duplicate elements must not replace old elements.

Elements are not key/value pairs.

Accessing an element can be almost as fast as performing a similar operation on an array.

Which of these classes provide the specified features?

A. LinkedList
B. TreeMap
C. HashMap
D. HashSet

8. class C1

{

static interface I

{

static class C2

{

}

}

public static void main(String a[])

{

C1.I.C2 ob1=new C1.I.C2();

System.out.println("object created");

}

}

What is the result of attempting to compile and run the program?

A. Prints object created
B. Compile time error
C. Runtime Excepion
D. None of the above

9. class C1

{

static class C2

{

static int i1;

}

public static void main(String a[])

{

System.out.println(C1.C2.i1);

}

}

What is the result of attempting to compile and run the program?

A. Prints 0
B. Compile time error
C. Runtime exception
D. None of the above

10. A signed data type has an equal number of non-zero positive and negative values available

A. True
B. False

Reference Link:
http://sg.sun.com/training/certification/java/scjp.xml


More Tests Report it

User Comments

why i only get 70? o_O (cuthangdat 2009-11-19)