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

Page:    1 / 10   
Total 138 questions

Click the Exhibit button.
Given the fully-qualified class names:
com.foo.bar.Dog
com.foo.bar.blatz.Book
com.bar.Car
com.bar.blatz.Sun
Which graph represents the correct directory structure for a JAR file from which those classes can be used by the compiler and JVM?

  • A. Jar C
  • B. Jar E
  • C. Jar A
  • D. Jar D
  • E. Jar B


Answer : C

A programmer has an algorithm that requires a java.util.List that provides an efficient implementation of add(0, object), but does NOT need to support quick random access.
What supports these requirements?

  • A. java.util.Queue
  • B. java.util.ArrayList
  • C. java.util.LinkedList
  • D. java.util.LinearList


Answer : C

Given:
11. public static Iterator reverse(List list) {
12. Collections.reverse(list);
13. return list.iterator();
14. }
15. public static void main(String[] args) {
16. List list = new ArrayList();
17. list.add("1"); list.add("2"); list.add("3");
18. for (Object obj: reverse(list))
19. System.out.print(obj + ", ");
20. }
What is the result?

  • A. 1, 2, 3,
  • B. The code runs with no output.
  • C. Compilation fails.
  • D. An exception is thrown at runtime.
  • E. 3, 2, 1,


Answer : C

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... msgs)
  • B. public void logIt(String * msgs)
  • C. public void logIt(String [] msgs)
  • D. public void logIt(String msg1, String msg2, String msg3)


Answer : A

Given:
11. abstract class Vehicle { public int speed() { return 0; }}
12. class Car extends Vehicle { public int speed() { return 60; }}
13. class RaceCar extends Car { public int speed() { return 150; }}
...
21. RaceCar racer = new RaceCar();
22. Car car = new RaceCar();
23. Vehicle vehicle = new RaceCar();
24. System.out.println(racer.speed() + ", " + car.speed()
25. + ", " + vehicle.speed());
What is the result?

  • A. 150, 150, 150
  • B. 150, 60, 0
  • C. An exception is thrown at runtime.
  • D. 0, 0, 0
  • E. Compilation fails.


Answer : A

Given:
10. abstract class A {
11. abstract void a1();
12. void a2() { }
13. }
14. class B extends A {
15. void a1() { }
16. void a2() { }
17. }
18. class C extends B { void c1() { } }
and:
A x = new B(); C y = new C(); A z = new C();
What are four valid examples of polymorphic method calls? (Choose four.)

  • A. x.a2();
  • B. x.a1();
  • C. z.a1();
  • D. z.a2();
  • E. z.c1();
  • F. y.c1();


Answer : A,B,C,D

Given:
1. public class Score implements Comparable<Score> {
2. private int wins, losses;
3. public Score(int w, int l) { wins = w; losses = l; }
4. public int getWins() { return wins; }
5. public int getLosses() { return losses; }
6. public String toString() {
7. return "<" + wins + "," + losses + ">";
8. }
9. // insert code here
10. }
Which method will complete this class?

  • A. public int compareTo(Object o){/*more code here*/}
  • B. public int compare(Score s1,Score s2){/*more code here*/}
  • C. public int compareTo(Score other){/*more code here*/}
  • D. public int compare(Object o1,Object o2){/*more code here*/}


Answer : C

A class games.cards.Poker is correctly defined in the jar file Poker.jar. A user wants to execute the main method of Poker on a UNIX system using the command: java games.cards.Poker
What allows the user to do this?

  • A. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jar
  • B. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java
  • C. Put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar
  • D. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java
  • E. put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/*.jar
  • F. put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jar


Answer : C

Click the Task button.



Answer :

Given:
10. public class Foo {
11. static int[] a;
12. static { a[0]=2; }
13. public static void main( String[] args ) {}
14. }
Which exception or error will be thrown when a programmer attempts to run this code?

  • A. java.lang.IllegalStateException
  • B. java.lang.ArrayIndexOutOfBoundsException
  • C. java.lang.StackOverflowError
  • D. java.lang.ExceptionInInitializerError


Answer : D

Given:
10. package com.sun.scjp;
11. public class Geodetics {
12. public static final double DIAMETER = 12756.32; // kilometers
13. }
Which two correctly access the DIAMETER member of the Geodetics class? (Choose two.)

  • A. import com.sun.scjp.Geodetics; public class TerraCarta { public double halfway() { return Geodetics.DIAMETER/2.0; } }
  • B. import static com.sun.scjp.Geodetics; public class TerraCarta{ public double halfway() { return DIAMETER/2.0; } }
  • C. package com.sun.scjp; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }
  • D. import static com.sun.scjp.Geodetics.*; public class TerraCarta { public double halfway() { return DIAMETER/2.0; } }


Answer : A,D

Given:
12. public class Test {
13. public enum Dogs {collie, harrier};
14. public static void main(String [] args) {
15. Dogs myDog = Dogs.collie;
16. switch (myDog) {
17. case collie:
18. System.out.print("collie ");
19. case harrier:
20. System.out.print("harrier ");
21. }
22. }
23. }
What is the result?

  • A. collie
  • B. Compilation fails.
  • C. collie harrier
  • D. An exception is thrown at runtime.
  • E. harrier


Answer : C

Click the Exhibit button.
Which statement is true about the classes and interfaces in the exhibit?

  • A. Compilation of class AImpl will fail because of an error in line 2.
  • B. Compilation of class C will fail because of an error in line 2.
  • C. Compilation will succeed for all classes and interfaces.
  • D. Compilation of class C will fail because of an error in line 6.


Answer : D

Given:
11. public class Ball{
12. public enum Color { RED, GREEN, BLUE };
13. public void foo(){
14. // insert code here
15. { System.out.println(c); }
16. }
17. }
Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?

  • A. for( Color c : Color.values() )
  • B. for( Color c = Color[0]; c <= Color[2]; c++ )
  • C. for( Color c = Color.RED; c <= Color.BLUE; c++ )
  • D. for( Color c = RED; c <= BLUE; c++ )
  • E. for( Color c ; c.hasNext() ; c.next() )


Answer : A

Which three statements are true? (Choose three.)

  • A. A public static method in class X can be called by a subclass of X without explicitly referencing the class X.
  • B. A method with the same signature as a private final method in class X can be implemented in a subclass of X.
  • C. A protected method in class X can be overridden by a subclass of A only if the subclass is in the same package as X.
  • D. A private static method can be called only within other static methods in class X.
  • E. A non-static public final method in class X can be overridden in any subclass of X.
  • F. A final method in class X can be abstract if and only if X is abstract.
  • G. A protected method in class X can be overridden by any subclass of X.


Answer : A,B,G

Page:    1 / 10   
Total 138 questions