1Z0-851 | The Secret of Oracle 1Z0-851 vce


Q11. Given:

1. public class Boxer1{

2. Integer i;

3. int x;

4. public Boxer1(int y) {

5. x = i+y;

6. System.out.println(x);

7. }

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

9. new Boxer1(new Integer(4));

10. }

11. }

What is the result?

A. The value "4" is printed at the command line.

B. Compilation fails because of an error in line 5.

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

D. A NullPointerException occurs at runtime.

E. A NumberFormatException occurs at runtime.

F. An IllegalStateException occurs at runtime.

Answer: D

Q12. Given:

1. interface DoStuff2 {

2. float getRange(int low, int high); }

3.

4. interface DoMore {

5. float getAvg(int a, int b, int c); }

6.

7. abstract class DoAbstract implements DoStuff2, DoMore { }

8.

9. class DoStuff implements DoStuff2 {

10. public float getRange(int x, int y) { return 3.14f; } }

11.

12. interface DoAll extends DoMore {

13. float getAvg(int a, int b, int c, int d); }

What is the result?

A. The file will compile without error.

B. Compilation fails. Only line 7 contains an error.

C. Compilation fails. Only line 12 contains an error.

D. Compilation fails. Only line 13 contains an error.

E. Compilation fails. Only lines 7 and 12 contain errors.

F. Compilation fails. Only lines 7 and 13 contain errors.

G. Compilation fails. Lines 7, 12, and 13 contain errors.

Answer: A

Q13. Given:

33. try {

34. // some code here

35. } catch (NullPointerException e1) {

36. System.out.print("a");

37. } catch (Exception e2) {

38. System.out.print("b");

39. } finally {

40. System.out.print("c");

41. }

If some sort of exception is thrown at line 34, which output is possible?

A. a

B. b

C. c

D. ac

E. abc

Answer: D

Q14. Given:

3. class Employee {

4. String name; double baseSalary;

5. Employee(String name, double baseSalary) {

6. this.name = name;

7. this.baseSalary = baseSalary;

8. }

9. }

10. public class SalesPerson extends Employee {

11. double commission;

12. public SalesPerson(String name, double baseSalary, double commission) {

13. // insert code here

14. }

15. }

Which two code fragments, inserted independently at line 13, will compile? (Choose two.)

A. super(name, baseSalary);

B. this.commission = commission;

C. super();

this.commission = commission;

D. this.commission = commission;

super();

E. super(name, baseSalary);

this.commission = commission;

F. this.commission = commission;

super(name, baseSalary);

G. super(name, baseSalary, commission);

Answer: AE

Q15. A company has a business application that provides its users with many different reports: receivables reports, payables reports, revenue projects, and so on. The company has just purchased some new, state-of-the-art, wireless printers, and a programmer has been assigned the task of enhancing all of the reports to use not only the company's old printers, but the new wireless printers as well. When the programmer starts looking into the application, the programmer discovers that because of the design of the application, it is necessary to make changes to each report to support the new printers. Which two design concepts most likely explain this situation? (Choose two.)

A. Inheritance

B. Low cohesion

C. Tight coupling

D. High cohesion

E. Loose coupling

F. Object immutability

Answer: BC

Q16. Given:

1. class Alligator {

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

3. int []x[] = {{1,2}, {3,4,5}, {6,7,8,9}};

4. int [][]y = x;

5. System.out.println(y[2][1]);

6. }

7. }

What is the result?

A. 2

B. 3

C. 4

D. 6

E. 7

F. Compilation fails.

Answer: E

Q17. Given:

1. class ClassA {

2. public int numberOfInstances;

3. protected ClassA(int numberOfInstances) {

4. this.numberOfInstances = numberOfInstances;

5. }

6. }

7. public class ExtendedA extends ClassA {

8. private ExtendedA(int numberOfInstances) {

9. super(numberOfInstances);

10. }

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

12. ExtendedA ext = new ExtendedA(420);

13. System.out.print(ext.numberOfInstances);

14. }

15. }

Which statement is true?

A. 420 is the output.

B. An exception is thrown at runtime.

C. All constructors must be declared public.

D. Constructors CANNOT use the private modifier.

E. Constructors CANNOT use the protected modifier.

Answer: A

Q18. Given:

1. public class Venus {

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

3. int [] x = {1,2,3};

4. int y[] = {4,5,6};

5. new Venus().go(x,y);

6. }

7. void go(int[]... z) {

8. for(int[] a : z)

9. System.out.print(a[0]);

10. }

11. }

What is the result?

A. 1

B. 12

C. 14

D. 123

E. Compilation fails.

F. An exception is thrown at runtime.

Answer: C

Q19. Given:

2. public class Hi {

3. void m1() { }

4. protected void() m2 { }

5. }

6. class Lois extends Hi {

7. // insert code here

8. }

Which four code fragments, inserted independently at line 7, will compile? (Choose four.)

A. public void m1() { }

B. protected void m1() { }

C. private void m1() { }

D. void m2() { }

E. public void m2() { }

F. protected void m2() { }

G. private void m2() { }

Answer: ABEF

Q20. Given:

11. public class ItemTest {

12. private final int id;

13. public ItemTest(int id) { this.id = id; }

14. public void updateId(int newId) { id = newId; }

15.

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

17. ItemTest fa = new ItemTest(42);

18. fa.updateId(69);

19. System.out.println(fa.id);

20. }

21. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. The attribute id in the ItemTest object remains unchanged.

D. The attribute id in the ItemTest object is modified to the new value.

E. A new ItemTest object is created with the preferred value in the id attribute.

Answer: A