Recall & Review
beginner
What is a static method in a Java interface?
A static method in a Java interface is a method with a body that belongs to the interface itself, not to instances of classes that implement the interface. It can be called using the interface name.
Click to reveal answer
beginner
How do you call a static method defined in a Java interface?
You call a static method in an interface using the interface name followed by the method name, like InterfaceName.methodName().
Click to reveal answer
intermediate
Can static methods in interfaces be overridden by implementing classes?
No, static methods in interfaces cannot be overridden by implementing classes because they belong to the interface itself, not to instances.
Click to reveal answer
intermediate
Why were static methods added to interfaces in Java 8?
Static methods were added to interfaces in Java 8 to allow utility or helper methods related to the interface without needing a separate class, improving code organization.
Click to reveal answer
beginner
Write a simple example of a static method inside a Java interface.
public interface Calculator {
static int add(int a, int b) {
return a + b;
}
}
You can call it with Calculator.add(5, 3); which returns 8.
Click to reveal answer
How do you invoke a static method defined in a Java interface?
✗ Incorrect
Static methods in interfaces belong to the interface itself and are called using the interface name.
Can a class override a static method defined in an interface?
✗ Incorrect
Static methods in interfaces belong to the interface and cannot be overridden by implementing classes.
When were static methods introduced in Java interfaces?
✗ Incorrect
Static methods in interfaces were introduced in Java 8 to allow utility methods inside interfaces.
Which of the following is true about static methods in interfaces?
✗ Incorrect
Static methods belong to the interface and can be called directly without an instance.
What is a common use case for static methods in interfaces?
✗ Incorrect
Static methods in interfaces are often used for utility or helper methods related to the interface.
Explain what static methods in interfaces are and how they differ from instance methods.
Think about who owns the method and how you call it.
You got /4 concepts.
Describe why static methods were added to interfaces in Java 8 and give an example.
Consider code organization and convenience.
You got /4 concepts.