Java Interfaces Quick Kit: 20 flashcards

All 20 flashcards from this kit, free and with no sign-up.

1. What is an **interface** in Java?

Show the answer

A blueprint of methods that a class promises to implement, defining *what* a class can do, not *how*.

2. What do interfaces declare?

Show the answer

Method **signatures** (names, parameters, return types) without bodies (prior to Java 8+).

3. Which keyword is used for a class to adopt an interface?

Show the answer

`implements`

4. What must a class do when it implements an interface?

Show the answer

Provide bodies for all its abstract methods.

5. Can a Java class implement multiple interfaces?

Show the answer

Yes, a class can implement multiple interfaces.

6. How does implementing multiple interfaces relate to multiple inheritance in Java?

Show the answer

It allows Java to achieve a form of multiple inheritance for behavior, as Java classes cannot extend multiple classes.

7. What are interface variables implicitly?

Show the answer

`public static final` (constants).

8. What are interface methods implicitly (before Java 8)?

Show the answer

`public abstract`.

9. What types of methods can interfaces have since Java 8?

Show the answer

`default` and `static` methods with bodies.

10. What types of methods can interfaces have since Java 9?

Show the answer

`private` helper methods, in addition to `default` and `static`.

11. Can you instantiate an interface directly?

Show the answer

No, you cannot. You create objects of classes that implement the interface.

12. In the example `interface Animal { void sound(); }`, what kind of method is `sound()`?

Show the answer

An abstract method.

13. In the example `interface Animal { default void sleep() { ... } }`, what kind of method is `sleep()`?

Show the answer

A default method (introduced in Java 8+).

14. What does `Animal a = new Dog();` demonstrate?

Show the answer

**Polymorphism**, where the variable type is the interface and the object is the concrete class.

15. Can an interface have constructors?

Show the answer

No, interfaces cannot have constructors.

16. Can an abstract class have constructors?

Show the answer

Yes, abstract classes can have constructors.

17. What kind of fields can an interface have?

Show the answer

Only constants (`public static final`).

18. What kind of fields can an abstract class have?

Show the answer

Any type of fields (constants, instance variables, etc.).

19. When should you generally use an interface over an abstract class?

Show the answer

When defining a shared capability or contract that multiple unrelated classes might implement.

20. When should you generally use an abstract class over an interface?

Show the answer

When defining a shared partial implementation for related classes that share a common base type.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages