Which code fragment, when inserted at line n1, enables …

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?

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?

A.
static void fly (Consumer<Bird> bird) {
bird :: fly ();
}

B.
static void fly (Consumer<? extends Bird> bird) {
bird.accept( ) fly ();
}

C.
static void fly (Supplier<Bird> bird) {
bird.get( ) fly ();
}

D.
static void fly (Supplier<? extends Bird> bird) {
LOST



Leave a Reply 3

Your email address will not be published. Required fields are marked *


smh

smh

C.
static void fly (Supplier bird) {
bird.get( ). fly ();

Berti John

Berti John

C. is correct