Java Standard Edition 5 Programmer Certified Professional Exam v6.0 (1z0-853)

Page:    1 / 25   
Total 366 questions

Given:
11. Float pi = new Float(3.14f);
12. if (pi > 3) {
13. System.out.print("pi is bigger than 3. ");
14. }
15. else {
16. System.out.print("pi is not bigger than 3. ");
17. }
18. finally {
19. System.out.println("Have a nice day.");
20. }
What is the result?

  • A. pi is not bigger than 3. Have a nice day.
  • B. pi is bigger than 3. Have a nice day.
  • C. pi is bigger than 3.
  • D. Compilation fails.
  • E. An exception occurs at runtime.


Answer : D

Given:
11. public static void append(List list) { list.add("0042"); }
12. public static void main(String[] args) {
13. List<Integer> intList = new ArrayList<Integer>();
14. append(intList);
15. System.out.println(intList.get(0));
16. }
What is the result?

  • A. An exception is thrown at runtime.
  • B. Compilation fails because of an error in line 14.
  • C. Compilation fails because of an error in line 13.
  • D. 0042
  • E. 42


Answer : D

Given:
10. interface Jumper { public void jump(); }
...
20. class Animal {}
...
30. class Dog extends Animal {
31. Tail tail;
32. }
...
40. class Beagle extends Dog implements Jumper{
41. public void jump() {}
42. }
...
50. class Cat implements Jumper{
51. public void jump() {}
52. }
Which three are true? (Choose three.)

  • A. Dog is-a Jumper
  • B. Beagle has-a Jumper
  • C. Cat has-a Animal
  • D. Dog is-a Animal
  • E. Cat is-a Jumper
  • F. Beagle has-a Tail
  • G. Cat is-a Animal


Answer : D,E,F

Given:
12. public class Yippee2 {
13.
14. static public void main(String [] yahoo) {
15. for(int x = 1; x < yahoo.length; x++) {
16. System.out.print(yahoo[x] + " ");
17. }
18. }
19. }
and the command line invocation:
java Yippee2 a b c
What is the result?

  • A. a b c
  • B. Compilation fails.
  • C. a b
  • D. An exception is thrown at runtime.
  • E. b c


Answer : E

Click the Task button.



Answer :

A programmer needs to create a logging method that can accept an arbitrary number of arguments. For example, it may be called in these ways: logIt("log message1"); logIt("log message2","log message3"); logIt("log message4","log message5","log message6");
Which declaration satisfies this requirement?

  • A. public void logIt(String msg1, String msg2, String msg3)
  • B. public void logIt(String [] msgs)
  • C. public void logIt(String * msgs)
  • D. public void logIt(String... msgs)


Answer : D

Click the Task button.



Answer :

Given:
1. import java.util.*;
2. public class PQ {
3. public static void main(String[] args) {
4. PriorityQueue<String> pq = new PriorityQueue<String>();
5. pq.add("carrot");
6. pq.add("apple");
7. pq.add("banana");
8. System.out.println(pq.poll() + ":" + pq.peek());
9. }
10. }
What is the result?

  • A. apple:apple
  • B. banana:apple
  • C. carrot:apple
  • D. apple:banana
  • E. carrot:banana
  • F. carrot:carrot


Answer : D

Given:
1. public class Threads3 implements Runnable {
2. public void run() {
3. System.out.print("running");
4. }
5. public static void main(String[] args) {
6. Thread t = new Thread(new Threads3());
7. t.run();
8. t.run();
9. t.start();
10. }
11. }
What is the result?

  • A. Compilation fails.
  • B. The code executes and prints "runningrunning".
  • C. The code executes and prints "runningrunningrunning".
  • D. The code executes and prints "running".
  • E. An exception is thrown at runtime.


Answer : C

Given:
int[] myArray = new int[] {1, 2, 3, 4, 5};
What allows you to create a list from this array?

  • A. List myList = Arrays.asList(myArray);
  • B. List myList = Collections.fromArray(myArray);
  • C. List myList = new ArrayList(myArray);
  • D. List myList = myArray.asList();


Answer : A

Given:
1. public class TestSeven extends Thread {
2. private static int x;
3. public synchronized void doThings() {
4. int current = x;
5. current++;
6. x = current;
7. }
8. public void run() {
9. doThings();
10. }
11.}
Which statement is true?

  • A. Compilation fails.
  • B. Declaring the doThings() method as static would make the class thread-safe.
  • C. Synchronizing the run() method would make the class thread-safe.
  • D. Wrapping the statements within doThings() in a synchronized(new Object()) { } block would make the class thread-safe.
  • E. An exception is thrown at runtime.
  • F. The data in variable "x" are protected from concurrent access problems.


Answer : B

Click the Task button.



Answer :

Given:
1. public class TestFive {
2. private int x;
3. public void foo() {
4. int current = x;
5. x = current + 1;
6. }
7. public void go() {
8. for(int i = 0; i < 5; i++) {
9. new Thread() {
10. public void run() {
11. foo();
12. System.out.print(x + ", ");
13. } }.start();
14. } }
Which two changes, taken together, would guarantee the output: 1, 2, 3, 4, 5, ? (Choose two.)

  • A. change the variable declaration on line 2 to private volatile int x;
  • B. wrap the code inside the foo() method with a synchronized( this ) block
  • C. change line 7 to public synchronized void go() {
  • D. wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }
  • E. move the line 12 print statement into the foo() method


Answer : B,E

Given:
11. public static void main(String[] args) {
12. String str = "null";
13. if (str == null) {
14. System.out.println("null");
15. } else (str.length() == 0) {
16. System.out.println("zero");
17. } else {
18. System.out.println("some");
19. }
20. }
What is the result?

  • A. An exception is thrown at runtime.
  • B. null
  • C. Compilation fails.
  • D. zero
  • E. some


Answer : C

Given:
11. public void genNumbers() {
12. ArrayList numbers = new ArrayList();
13. for (int i=0; i<10; i++) {
14. int value = i * ((int) Math.random());
15. Integer intObj = new Integer(value);
16. numbers.add(intObj);
17. }
18. System.out.println(numbers);
19. }
Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?

  • A. Line 19
  • B. Line 16
  • C. Line 17
  • D. The object is NOT a candidate for garbage collection.
  • E. Line 18


Answer : A

Page:    1 / 25   
Total 366 questions