1Z0-851 | A Review Of Realistic 1Z0-851 exam dumps


Q121. Given:

11. class Alpha {

12. public void foo() { System.out.print("Afoo "); }

13. }

14. public class Beta extends Alpha {

15. public void foo() { System.out.print("Bfoo "); }

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

17. Alpha a = new Beta();

18. Beta b = (Beta)a;

19. a.foo();

20. b.foo();

21. }

22. }

What is the result?

A. Afoo Afoo

B. Afoo Bfoo

C. Bfoo Afoo

D. Bfoo Bfoo

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: D

Q122. Which two code fragments will execute the method doStuff() in a separate thread? (Choose two.)

A. new Thread() {

public void run() { doStuff(); }

};

B. new Thread() {

public void start() { doStuff(); }

};

C. new Thread() {

public void start() { doStuff(); }

}.run();

D. new Thread() {

public void run() { doStuff(); }

}.start();

E. new Thread(new Runnable() {

public void run() { doStuff(); }

}).run();

F. new Thread(new Runnable() {

public void run() { doStuff(); }

}).start();

Answer: DF

Q123. Given:

1. public class TestString1 {

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

3. String str = "420";

4. str += 42;

5. System.out.print(str);

6. }

7. }

What is the output?

A. 42

B. 420

C. 462

D. 42042

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: D

Q124. Given:

1. package com.company.application;

2.

3. public class MainClass {

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

5. }

And MainClass exists in the /apps/com/company/application directory. Assume the CLASSPATH environment variable is set to "." (current directory). Which two java commands entered at the command line will run MainClass? (Choose two.)

A. java MainClass if run from the /apps directory

B. java com.company.application.MainClass if run from the /apps directory

C. java -classpath /apps com.company.application.MainClass if run from any directory

D. java -classpath . MainClass if run from the /apps/com/company/application directory

E. java -classpath /apps/com/company/application:. MainClass if run from the /apps directory

F. java com.company.application.MainClass if run from the /apps/com/company/application directory

Answer: BC

Q125. Given:

11. public abstract class Shape {

12. private int x;

13. private int y;

14. public abstract void draw();

15. public void setAnchor(int x, int y) {

16. this.x = x;

17. this.y = y;

18. }

19. }

Which two classes use the Shape class correctly? (Choose two.)

A. public class Circle implements Shape {

private int radius;

}

B. public abstract class Circle extends Shape {

private int radius;

}

C. public class Circle extends Shape {

private int radius;

public void draw();

}

D. public abstract class Circle implements Shape {

private int radius;

public void draw();

}

E. public class Circle extends Shape {

private int radius;

public void draw() {/* code here */}

F. public abstract class Circle implements Shape {

private int radius;

public void draw() { /* code here */ }

Answer: BE

Q126. Given:

11. static class A {

12. void process() throws Exception { throw new Exception(); }

13. }

14. static class B extends A {

15. void process() { System.out.println("B"); }

16. }

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

18. new B().process();

19. }

What is the result?

A. B

B. The code runs with no output.

C. Compilation fails because of an error in line 12.

D. Compilation fails because of an error in line 15.

E. Compilation fails because of an error in line 18.

Answer: A

Q127. Given:

1. public class Mule {

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

3. boolean assert = true;

4. if(assert) {

5. System.out.println("assert is true");

6. }

7. }

8. }

Which command-line invocations will compile?

A. javac Mule.java

B. javac -source 1.3 Mule.java

C. javac -source 1.4 Mule.java

D. javac -source 1.5 Mule.java

Answer: B

Q128. 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. An exception is thrown at runtime.

C. Synchronizing the run() method would make the class thread-safe.

D. The data in variable "x" are protected from concurrent access problems.

E. Declaring the doThings() method as static would make the class thread-safe.

F. Wrapping the statements within doThings() in a synchronized(new Object()) { } block would make the

class thread-safe.

Answer: E

Q129. Given:

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

12. Integer i = new Integer(1) + new Integer(2);

13. switch(i) {

14. case 3: System.out.println("three"); break;

15. default: System.out.println("other"); break;

16. }

17. }

What is the result?

A. three

B. other

C. An exception is thrown at runtime.

D. Compilation fails because of an error on line 12.

E. Compilation fails because of an error on line 13.

F. Compilation fails because of an error on line 15.

Answer: A

Q130. Given:

1. class TestException extends Exception { }

2. class A {

3. public String sayHello(String name) throws TestException {

4. if(name == null) throw new TestException();

5. return "Hello " + name;

6. }

7. }

8. public class TestA {

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

10. new A().sayHello("Aiko");

11. }

12. }

Which statement is true?

A. Compilation succeeds.

B. Class A does not compile.

C. The method declared on line 9 cannot be modified to throw TestException.

D. TestA compiles if line 10 is enclosed in a try/catch block that catches TestException.

Answer: D