Recall & Review
beginner
What is an interface in Java?
An interface in Java is a blueprint that defines methods without implementations. Classes can implement interfaces to promise they provide those methods.
Click to reveal answer
beginner
How do you declare that a class implements an interface?Use the keyword <code>implements</code> after the class name, followed by the interface name. For example: <code>class Dog implements Animal</code>.Click to reveal answer
intermediate
Can a class implement multiple interfaces in Java?Yes, a class can implement multiple interfaces by listing them separated by commas. For example: <code>class Robot implements Walkable, Talkable</code>.Click to reveal answer
intermediate
What happens if a class does not implement all methods of an interface?The class must be declared abstract, or else the compiler will give an error because it did not fulfill the interface contract.Click to reveal answer
advanced
Why use interfaces instead of abstract classes?
Interfaces allow multiple inheritance of type, letting a class promise to provide many behaviors. Abstract classes are for shared code and single inheritance.Click to reveal answer
Which keyword is used to make a class follow an interface in Java?
✗ Incorrect
The keyword
implements is used for a class to follow an interface.If a class implements an interface, what must it do?
✗ Incorrect
A class must implement all methods declared in the interface unless it is abstract.
Can a Java class implement more than one interface?
✗ Incorrect
Java allows multiple interfaces to be implemented by a class, separated by commas.
What is the main purpose of interfaces?
✗ Incorrect
Interfaces define a contract of methods without implementations that classes promise to provide.
If a class does not implement all interface methods, what must it be declared as?
✗ Incorrect
The class must be declared abstract if it does not implement all interface methods.
Explain how to implement an interface in a Java class and what rules must be followed.
Think about the syntax and what the compiler expects.
You got /3 concepts.
Describe the difference between interfaces and abstract classes in Java.
Consider how Java supports multiple behaviors.
You got /3 concepts.