SCJP Certification Questions Test # 3

Oracle Certification Program Candidate Guide

. Given:

1. public class ArrayTest {

2. public static void main (String[] args) {

3. Object[] ov;

4. String[] sa = { "Green", "Blue", "Red" };

5. ov = sa;

6. System.out.println("Color = " + ov[1]);

7. }

8. }

What is the result?

A. fails to compile

B. prints Color=Blue

C. prints Color=Green

D. generates an exception at runtime


2. Given:

1. public class OuterClass {

2. private double d1 = 1.0;

3. //insert code here

4. }

You need to insert an inner class declaration at line 3. Which two inner class declarations are valid?(Choose two.)

A. class InnerOne{
public static double methoda() {return d1;}
}

B. public class InnerOne{
static double methoda() {return d1;}
}

C. private class InnerOne{
double methoda() {return d1;}
}

D. static class InnerOne{
protected double methoda() {return d1;}
}

E. abstract class InnerOne{
public abstract double methoda();
}


3. Given:

1. public class X {

2. public void m(Object x) {

3. x = new Integer(99);

4. Integer y = (Integer)x;

5. y = null;

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

7. }

8. }

When is the Integer object, created in line 3, eligible for garbage collection?

A. never

B. just after line 4

C. just after line 5

D. just after line 6 (that is, as the method returns)

E. when the calling method sets the argument it passed into this method to null


4. Which is a valid identifier?

A. false

B. default

C. _object

D. a-class


5. Which two are equivalent? (Choose two.)

A. 12>4

B. 12/4

C. 12*4

D. 12>>2

E. 12/2^2

F. 12>>>1


6. Which two demonstrate a "has a" relationship? (Choose two.)

A. public interface Person{ }
public class Employee extends Person{ }

B. public interface Shape{ }
public interface Rectangle extends Shape{ }

C. public interface Colorable{ }
public class Shape implements Colorable{ }

D. public class Species{ }
public class Animal{private Species species;}

E. interface Component{ }
class Container implements Component{
private Component[] children;
}


7. Given

double pi = Math.PI;
Which two are valid ways to round pi to an int?(Choose two.)

A. int p = pi;

B. int p = Math.round(pi);

C. int p = (int)Math.round(pi);

D. int p = (int)Math.min(pi + 0.5d);

E. int p = (int)Math.floor(pi + 0.5d);


8. Which two statements are true for the class java.util.TreeSet? (Choose two.)

A. The elements in the collection are ordered.

B. The collection is guaranteed to be immutable.

C. The elements in the collection are guaranteed to be unique.

D. The elements in the collection are accessed using a unique key.

E. The elements in the collection are guaranteed to be synchronized



(No Answers for this Test)

Answers # 3

1. prints Color=Blue

Because Object Class is Super Class of Every Class therefore, String array object can be assigned to Object array. For example ,

class Super{}

class Derived extends Super{}

class Test{

public static void main(String []argv)

{

Super supobj = new Derived();

}

}

2. C&E

private class InnerOne

{
double methoda()

{

return d1;

}
}

And,

abstract class InnerOne

{
public abstract double methoda();
}


other options are false because a non-static inner class cannot have static context i.e for options A and B. for D it is false because the variable cannot be referenced from static context, because of static inner class.

3. D just after line 6 (that is, as the method returns)

Because the Object x has local scope i.e it is in the method therefore it will be garbage

Collected after method returns to caller.

4. C _object

options A is boolean literal and B is keywords for Java where as – (miuns) is not allowed as identifier for object or variablebane. So C is correct.

5. B and D

Because 12 >> 2 gives 3 and 12/4 also gives 3

12 represented as 8 4 2 1 0

1 1 0 0 0 >> 2

0 0 1 1 0 == 3

6. D and E

public class Species{ }
public class Animal{private Species species;}

interface Component{ }
class Container implements Component{
private Component[] children;
}


7. C and E

int p = (int)Math.round(pi);

int p = (int)Math.floor(pi + 0.5d);

8. A and C

The elements in the collection are ordered.

The elements in the collection are guaranteed to be unique.

No comments: