exam questions

Exam 1z0-809 All Questions

View all questions & answers for the 1z0-809 exam

Exam 1z0-809 topic 1 question 7 discussion

Actual exam question from Oracle's 1z0-809
Question #: 7
Topic #: 1
[All 1z0-809 Questions]

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) { bird::fly(); }
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
SAMUEL_TARUS
5 months ago
The correct answer is A. static void fly (Consumer<Bird> bird) { bird :: fly (); }. Here's a breakdown of why: Method Signature: The Birdie class needs a static method fly that takes a functional interface as a parameter. Functional Interface: The Consumer interface is suitable because it accepts a single parameter (a Bird in this case) and doesn't return a value. Method Body: The method body should call the fly method of the Bird object passed as a parameter. The :: operator is used to reference the fly method as a method reference.
upvoted 1 times
...
asdfjhfgjuaDCV
11 months ago
C is the answer
upvoted 1 times
...
steefaand
12 months ago
Selected Answer: C
Answer is C
upvoted 1 times
...
r1muka5
1 year, 11 months ago
Answer is C.
upvoted 1 times
...
dexdinh91
2 years, 4 months ago
lack a dot, shoule be compile error
upvoted 1 times
...
mevlt
2 years, 11 months ago
The answer is C but it must have a period(.) after bird.get(). Eventually bird.get().fly()
upvoted 3 times
...
WilsonKKerll
2 years, 11 months ago
public class ch7 { public static void main(String[] args) { fly(() -> new Bird()); fly(Penguin::new); } static void fly(Supplier<Bird> bird) { bird.get().fly(); } } class Bird { public void fly() { System.out.println("Can fly"); } } class Penguin extends Bird { public void fly() { System.out.println("Cannot fly"); } }
upvoted 1 times
...
YasinGaber
2 years, 11 months ago
Compiling the code with answer C (it is the right answer) results in following output: Can flyCannot fly
upvoted 2 times
...
AVB22
3 years, 2 months ago
C, tested
upvoted 1 times
...
pul26
4 years, 1 month ago
package birdie; import java.util.function.Supplier; class Bird { public void fly() { System.out.print("Can fly"); } } class Penguin extends Bird { public void fly() { System.out.print("Cannot fly"); } } public class Birdie { public static void main(String[] args) { fly(() -> new Bird()); fly(Penguin::new); } static void fly(Supplier<Bird> bird) { bird.get().fly(); } }
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago