0
0
Javaprogramming~5 mins

Interface declaration in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Ainterface
Bclass
Cimplements
Dextends
How does a class promise to follow an interface's rules?
Aoverrides
Bextends
Cinherits
Dimplements
Can interfaces have method bodies in Java 8 and later?
AOnly for abstract methods
BNo, never
CYes, for default and static methods
DOnly for private methods
Which of these is true about interfaces?
AInterfaces define method signatures without bodies by default
BInterfaces can contain constructors
CInterfaces cannot extend other interfaces
DInterfaces can be instantiated directly
What keyword allows an interface to inherit from another interface?
Aimplements
Bextends
Cinherits
Duses
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.