Interfaces - Default Methods QuizJ8 Home « Interfaces - Default Methods Quiz

OO Concepts Quiz 11

The quiz below tests your knowledge of the material learnt in OO Concepts - Lesson 11 - Interfaces - Default Methods.

Question 1 : Why were default methods introduced in Java8?
- Default methods introduced in Java8 to allow interface updates without breaking implementation contract.
Question 2 : We can put implementation code into static interface methods?
- We can put implementation code into static interface methods
Question 3 : Is the following code snippet valid?

public interface MyMouseListener extends EventListener {
    default void mouseClicked(MouseEvent e) {};
    void mousePressed(MouseEvent e) {};
    default void mouseReleased(MouseEvent e) {};
    default void mouseEntered(MouseEvent e) {};
    default void mouseExited(MouseEvent e) {};
}
- This code snippet is invalid as non-default interface methods cannot have a body.
Question 4 : Interface default methods have a body
- Interface default methods DO HAVE a body
Question 5 : Interface static methods remove the need for interface static utility companion classes?
- Static utility companion classes can be coded directly in interfaces from Java8.
Quiz Progress Bar Please select an answer


What's Next?

In the next quiz we test your knowledge of interface default methods which were introduced in Java8.