Online Test - SCJP sample test #2

Sun Certified Java Programmer sample test #2.

This foundation certification is for programmers interested in demonstrating proficiency in the fundamentals of the Java programming language.

To achieve this certification, candidates must successfully complete one exam.

The sample test is just for those who want are preparing SCJP.

1. class C{
static int f1(int i) {
System.out.print(i + ",");
return 0;
}
public static void main (String[] args) {
int i = 0;
i = i++ + f1(i);
System.out.print(i);
}}

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

2. class C{
static String m(int i) {return "int";}

static String m(float i) {return "float";}

public static void main (String[] args) {
long a1 = 1; double b1 = 2;
System.out.print(m(a1)+","+ m(b1));
}
}

A. Prints: float,double
B. Prints: float,float
C. Prints: double,float
D. Compile time error
E. None of the above

3. class C
{
public static void main(String a[])
{
C c1=new C();
C c2=m1(c1);
C c3=new C();
c2=c3; //6
anothermethod();
}
static C m1(C ob1){
ob1 =new C();
return ob1;
}
}
After line 6, how many objects are eligible for garbage collection?

A. 1
B. 2
C. 3
D. 4

4. StringBuffer s1 = new StringBuffer("abc");
StringBuffer s2 = s1;
StringBuffer s3 = new StringBuffer("abc");
How many objects are created ?

A. 0
B. 1
C. 2
D. 3

5. class c2
{
{
System.out.println("initializer");
}
public static void main(String a[])
{
System.out.println("main");
c2 ob1=new c2();
}
}

What is the result run the above code?

A. Prints main and initializer
B. Prints initializer and main
C. Compile time error
D. None of the above

6. class c1
{
public static void main(String a[])
{
c1 ob1=new c1();
Object ob2=ob1;
System.out.println(ob2 instanceof Object);
System.out.println(ob2 instanceof c1);
}
}

A. Prints true,false
B. Prints false,true
C. Prints true,true
D. Compile time error

7. class A extends Thread {
private int i;
public void run() {i = 1;}
public static void main(String[] args) {
A a = new A();
a.run();
System.out.print(a.i);
}}

A. Prints nothing
B. Prints: 1
C. Prints: 01
D. Compile time error

8. class bike
{
}
class arr extends bike{
public static void main(String[] args) {
arr[] a1=new arr[2];
bike[] a2;
a2=a1; //3
arr[] a3;
a3=a1; //5
}}

A. Compile time error at line 3
B. Compile time error at line 5
C. Runtime exception
D. The code runs fine

9. class C{
public static void main (String[] args) {
String s1="hjhh"; // 1
String s2="\u0002"; //2
String s3="'\\'"; //3
}}

A. Compile time error at line 1
B. Compile time error at line 2
C. Compile time error at line 3
D. Runtime exception
E. The code runs without any error

10. Which data type is wider for the purpose of casting: float or long?

A. Float
B. Long

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


More Tests Report it

User Comments

hi you have given questions where is explanation (subbareddy 2009-10-24)