Free Oracle 1Z0-809 Exam Questions (page: 3)

Which two reasons should you use interfaces instead of abstract classes? (Choose two.)

  1. You expect that classes that implement your interfaces have many common methods or fields, or require access modifiers other than public.
  2. You expect that unrelated classes would implement your interfaces.
  3. You want to share code among several closely related classes.
  4. You want to declare non-static on non-final fields.
  5. You want to take advantage of multiple inheritance of type.

Answer(s): B,E


Reference:

https://books.google.com.br/books?id=nS2tBQAAQBAJ&pg=PT235&lpg=PT235&dq=You+want+to+share+code+among+several+closely+related+classes.&source=bl&ots=3oYOu2XXN-&sig=uVFS0KB15BqyEgghXnnjJSUdcrE&hl=pt-BR&sa=X&ved=0ahUKEwjlsKe-n6baAhVEhZAKHeiEDTgQ6AEIMDAB#v=onepage&q=You%20want%20to%20share%20code%20among%20several%20closely%20related%20classes.&f=false



Given:
public class Counter {
public static void main (String[ ] args) {
int a = 10;
int b = -1;
assert (b >=1) : “Invalid Denominator”;
int с = a / b;
System.out.println (c);
}
}

What is the result of running the code with the –ea option?

  1. -10
  2. 0
  3. An AssertionError is thrown.
  4. A compilation error occurs.

Answer(s): C



Given:
class Bird {
public void fly () { System.out.print(“Can fly”); }
}
class Penguin extends Bird {
public void fly () { System.out.print(“Cannot fly”); }
}

and the code fragment:

class Birdie {
public static void main (String [ ] args) {
fly( ( ) -> new Bird ( ));
fly (Penguin : : new);
}
/* line n1 */
}

Which code fragment, when inserted at line n1, enables the Birdie class to compile?

  1. static void fly (Consumer<Bird> bird) { bird :: fly ();
    }
  2. static void fly (Consumer<? extends Bird> bird) { bird.accept( ) fly ();
    }
  3. static void fly (Supplier<Bird> bird) { bird.get( ) fly ();
    }
  4. static void fly (Supplier<? extends Bird> bird) {
    LOST

Answer(s): C



Given:
1. abstract class Shape {
2. Shape ( ) { System.out.println (“Shape”); }
3. protected void area ( ) { System.out.println (“Shape”); }
4. }
5.
6. class Square extends Shape {
7. int side;
8. Square int side {
9. /* insert code here */
10. this.side = side;
11. }
12. public void area ( ) { System.out.println (“Square”); }
13. }
14. class Rectangle extends Square {
15. int len, br;
16. Rectangle (int x, int y) {
17. /* insert code here */
18. len = x, br = y;
19. }
20. void area ( ) { System.out.println (“Rectangle”); }
21. }

Which two modifications enable the code to compile? (Choose two.)

  1. At line 1, remove abstract
  2. At line 9, insert super ( );
  3. At line 12, remove public
  4. At line 17, insert super (x);
  5. At line 17, insert super (); super.side = x;
  6. At line 20, use public void area ( ) {

Answer(s): D,F






Post your Comments and Discuss Oracle 1Z0-809 exam prep with other Community members:

1Z0-809 Exam Discussions & Posts