1Z0-851 | 10 Tips For Down to date 1Z0-851 exam dumps


Q1. Given:

11. public static void test(String str) {

12. int check = 4;

13. if (check = str.length()) {

14. System.out.print(str.charAt(check -= 1) +", ");

15. } else {

16. System.out.print(str.charAt(0) + ", ");

17. }

18. } and the invocation:

21. test("four");

22. test("tee");

23. test("to");

What is the result?

A. r, t, t,

B. r, e, o,

C. Compilation fails.

D. An exception is thrown at runtime.

Answer: C

Q2. Click the Exhibit button. Given: ClassA a = new ClassA(); a.methodA(); What is the result?

A. Compilation fails.

B. ClassC is displayed.

C. The code runs with no output.

D. An exception is thrown at runtime.

Answer: D

Q3. Given:

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

12. for (int i = 0; i <= 10; i++) {

13. if (i > 6) break;

14. }

15. System.out.println(i);

16. }

What is the result?

A. 6

B. 7

C. 10

D. 11

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: E

Q4. Click the Exhibit button. What two must the programmer do to correct the compilation errors? (Choose two.)

A. insert a call to this() in the Car constructor

B. insert a call to this() in the MeGo constructor

C. insert a call to super() in the MeGo constructor

D. insert a call to super(vin) in the MeGo constructor

E. change the wheelCount variable in Car to protected

F. change line 3 in the MeGo class to super.wheelCount = 3;

Answer: DE

Q5. Which two scenarios are NOT safe to replace a StringBuffer object with a StringBuilder object? (Choose two.)

A. When using versions of Java technology earlier than 5.0.

B. When sharing a StringBuffer among multiple threads.

C. When using the java.io class StringBufferInputStream.

D. When you plan to reuse the StringBuffer to build more than one string.

Answer: AB

Q6. 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. move the line 12 print statement into the foo() method

B. change line 7 to public synchronized void go() {

C. change the variable declaration on line 2 to private volatile int x; D. wrap the code inside the foo() method with a synchronized( this ) block

D. wrap the for loop code inside the go() method with a synchronized block synchronized(this) { // for loop code here }

Answer: AD

Q7. 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 compareTo(Score other){/*more code here*/}

C. public int compare(Score s1,Score s2){/*more code here*/}

D. public int compare(Object o1,Object o2){/*more code here*/}

Answer: B

Q8. Given:

11. String test = "Test A. Test B. Test C.";

12. // insert code here

13. String[] result = test.split(regex);

Which regular expression, inserted at line 12, correctly splits test into "Test A", "Test B", and "Test C"?

A. String regex = "";

B. String regex = " ";

C. String regex = ".*";

D. String regex = "\s";

E. String regex = "\.\s*";

F. String regex = "\w[ .] +";

Answer: E

Q9. 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 compareTo(Score other){/*more code here*/}

C. public int compare(Score s1,Score s2){/*more code here*/}

D. public int compare(Object o1,Object o2){/*more code here*/}

Answer: B

Q10. Which statement is true?

A. A class's finalize() method CANNOT be invoked explicitly.

B. super.finalize() is called implicitly by any overriding finalize() method.

C. The finalize() method for a given object is called no more than once by the garbage collector.

D. The order in which finalize() is called on two objects is based on the order in which the two objects

became finalizable.

Answer: C