Java object-oriented design quiz

  • Admin
  • 1 min read

Nine questions on inheritance, polymorphism, interfaces, abstract classes and packages.

Java

Java object-oriented design quiz

9 questions, instant feedback

Question 1 of 9
Question 1 of 9 Which keyword inherits from a class?
Why this is the answer

A class extends one superclass. It implements any number of interfaces.

Question 2 of 9
Question 2 of 9 What does @Override document?
Why this is the answer

The annotation makes the compiler verify the signature matches something inherited, catching typos.

Question 3 of 9
Question 3 of 9 What is polymorphism in practice?
Why this is the answer

The variable's declared type decides what compiles; the object's actual class decides which implementation runs.

Question 4 of 9
Question 4 of 9 Can a class extend more than one class in Java?
Why this is the answer

Java has single inheritance for classes to avoid the diamond problem. Interfaces provide the multiple-type behaviour.

Question 5 of 9
Question 5 of 9 What is an abstract method?
Why this is the answer

An abstract method declares a signature without a body, and the class containing it must be abstract.

Question 6 of 9
Question 6 of 9 When should you prefer an interface to an abstract class?
Why this is the answer

Interfaces describe capability without imposing a hierarchy, and a class can implement several.

Question 7 of 9
Question 7 of 9 What does super refer to?
Why this is the answer

super calls the parent constructor or a parent method that the subclass has overridden.

Question 8 of 9
Question 8 of 9 What is the purpose of a package?
Why this is the answer

Packages namespace classes and let package-private members be shared within the package only.

Question 9 of 9
Question 9 of 9 What does the Liskov substitution principle require?
Why this is the answer

If a subclass cannot honour the parent's contract, the inheritance is wrong and composition is usually better.

Your answers stay in this browser. Nothing is sent to a server.