Recall & Review
beginner
What is an interface in Java?
An interface in Java is a blueprint that defines a set of abstract methods (methods without a body) that a class can implement. It specifies what a class must do, but not how.Click to reveal answer
beginner
How do you declare an interface in Java?
You declare an interface using the keyword
interface followed by the interface name and a block containing method signatures. Example:<br>public interface MyInterface {
void myMethod();
}Click to reveal answer
intermediate
Can interfaces have method bodies in Java?
Since Java 8, interfaces can have default methods with bodies using the
default keyword, and static methods with bodies. But regular abstract methods do not have bodies.Click to reveal answer
beginner
What keyword does a class use to implement an interface?A class uses the <code>implements</code> keyword to promise it will provide code for all the methods declared in the interface.Click to reveal answer
intermediate
Can an interface extend another interface?
Yes, an interface can extend one or more other interfaces using the
extends keyword. This allows combining multiple interfaces into one.Click to reveal answer
Which keyword is used to declare an interface in Java?
✗ Incorrect
The keyword
interface is used to declare an interface.How does a class promise to follow an interface's rules?
✗ Incorrect
A class uses
implements to promise it will provide all methods from the interface.Can interfaces have method bodies in Java 8 and later?
✗ Incorrect
Since Java 8, interfaces can have default and static methods with bodies.
Which of these is true about interfaces?
✗ Incorrect
Interfaces define method signatures without bodies by default.
What keyword allows an interface to inherit from another interface?
✗ Incorrect
Interfaces use
extends to inherit from other interfaces.Explain how to declare an interface and how a class uses it.
Think about the keywords and what each part means.
You got /4 concepts.
Describe the difference between abstract methods and default methods in interfaces.
Consider what changed in Java 8.
You got /3 concepts.