← Quiz: Abstract Classes and Interfaces: all 10 questions
Quiz: Abstract Classes and Interfaces · Question 4 of 10
What does this print? (code)
What does this print?
interface Greeter { default String hi() { return "hi"; } }
class Friend implements Greeter { }
public class Main {
public static void main(String[] args) {
System.out.println(new Friend().hi());
}
}
- A.hi
- B.null
- C.Error: hi() not implemented
- D.Friend
Answer & explanation
Correct answer: hi
Default methods have a body, so implementing classes get them for free.
Can you get the rest right without peeking?
Take the timed Quiz: Abstract Classes and Interfaces quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →