Today, I’m going to review my online test, chapter 1 of Oracle Certified Associate (OCA), provided by SYBEX. If you need to access to this online resources, you need to buy their book first. See https://sybextestbanks.wiley.com/.
Question 8
Given the following class, which of the following calls print out Blue Jay
?
(Choose all that apply)
java BirdDisplay Sparrow Blue Jay
java BirdDisplay Sparrow "Blue Jay"
java BirdDisplay Blue Jay Sparrow
java BirdDisplay "Blue Jay" Sparrow
java BirdDisplay.class Sparrow "Blue Jay"
java BirdDisplay.class "Blue Jay" Sparrow
The answer is B. Choice A is wrong because the program takes 3 arguments,
and the argument at index 1, Blue
, will be printed. Choice B is correct
because "Blue Jay"
is a string which is considered as one argument. The same
logic: the choice C will print Jay
; the choice D will print Sparrow
. As for
choices E and F, they won’t work because java uses the compiled class’ name
without extension, so java BirdDisplay.class
is illegal. If you do so, you’ll
see the error message:
Error: Could not find or load main class BirdDisplay.class.
Question 19
Suppose we have a class named Rabbit
. Which of the following statements are
true? (Choose all that apply)
1
2
3
4
5
6
7
8
9
10
11
12
13
public class Rabbit {
public static void main(String[] args) {
Rabbit one = new Rabbit();
Rabbit two = new Rabbit();
Rabbit three = one;
one = null;
Rabbit four = one;
three = null;
two = null;
two = new Rabbit();
System.gc();
}
}
- The
Rabbit
object from line 3 is first eligible for garbage collection immediately following line 6. - The
Rabbit
object from line 3 is first eligible for garbage collection immediately following line 8. - The
Rabbit
object from line 3 is first eligible for garbage collection immediately following line 12. - The
Rabbit
object from line 4 is first eligible for garbage collection immediately following line 9. - The
Rabbit
object from line 4 is first eligible for garbage collection immediately following line 11. - The
Rabbit
object from line 4 is first eligible for garbage collection immediately following line 12.
The answer is BD. An object is no longer reachable, i.e. eligible for garbage collection, when one of two situations occurs:
- The object no longer has any references pointing to it.
- All references to the object have gone out of scope.
So in the question, in line 6, object one
revoked its reference, but that
rabbit is still referenced by three
until line 8: so AC are wrong, and B is
correct. As for rabbit two
, the instance created in line 4 has no reference
immediately following line 9, so D is correct. In line 10, a new instance had
been created, but that is not the same instance as the one created in line 4.
Question 22
Which of the following are true statements? (Choose all that apply)
- Java allows operator overloading.
- Java code compiled on Windows can run on Linux.
- Java has pointers to specific locations in memory.
- Java is a procedural language.
- Java is an object-oriented language.
- Java is a functional programming language.
The answer is BE. C++ has operator overloading and pointers. Java made a point of not having either. Java does have references to objects, but these are pointing to an object that can move around memory. Option B is correct because Java is platform independent. As for option F, while it does support some parts of functional programming, these occur within a class, so Java is not a functional programming language.