Skip to content
codinganthem

Object-oriented programming skill check

Practise object-oriented design: encapsulation, inheritance, polymorphism, abstract classes versus interfaces, composition, and the SOLID principles.

15

Questions

11 min

Timer can't pause

Multiple choice

One answer out of four

Choose a level

Topics

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Abstraction
  • Interfaces and abstract classes
  • Composition
  • Overloading and overriding
  • SOLID

Do

Use scratch paper or a notepad to work things out. Skip a question and come back to it later.

Don't

Look up answers during the check. Open the check in more than one tab or window.

Easy · 15 questions · 11 min

By starting, you agree to the Terms and Privacy Policy.

Start practice

Practice checks each answer as you go, with an explanation. The exam is checked when you submit; 9 of 15 passes and earns a certificate.

Checking your levels…

Certificates come from the certified exam: pass with 9 of 15 while signed in. View a sample certificate.

Sample Object-oriented programming questions with answers

These are never used in a check, so seeing their answers here won't give anything away.

  1. Question 1 · Easy · Encapsulation

    Which design choice best demonstrates the principle of encapsulation in an object-oriented class?
    1. A.Keeping class fields private and providing controlled access via methods to enforce invariants
    2. B.Defining public fields so that external callers can directly inspect and modify state without overhead
    3. C.Splitting a class into multiple derived subclasses to distribute field access across a hierarchy
    4. D.Making all member variables final static constants so their values cannot change after compilation
    Show answer

    A. Keeping class fields private and providing controlled access via methods to enforce invariants

    Encapsulation bundles data and the methods that operate on that data within a class while restricting direct access to internal state. This ensures that any mutation preserves class invariants and hides internal representation details.
  2. Question 2 · Easy · Inheritance

    In object-oriented design, when is it most appropriate to use class inheritance between class Derived and class Base?
    1. A.When Derived needs to share helper methods from Base without sharing a domain type relationship
    2. B.When Derived has an 'is-a' relationship with Base and can substitute for Base in all contexts
    3. C.When Derived has a 'has-a' relationship with Base and delegates its work to Base
    4. D.When Base has private fields that Derived needs direct read and write access to
    Show answer

    B. When Derived has an 'is-a' relationship with Base and can substitute for Base in all contexts

    Inheritance represents an 'is-a' relationship where the derived class specializes the base class and adheres to behavioral subtyping. When only code reuse or containment is needed, composition ('has-a') is preferred.
  3. Question 3 · Moderate · Composition

    Why is object composition frequently favored over class inheritance when designing flexible object hierarchies?
    1. A.Composition enforces dynamic method dispatch at compile time rather than runtime.
    2. B.Composition allows behaviors to be swapped dynamically at runtime and avoids tightly coupling internal implementation details.
    3. C.Composition eliminates the need for interface definitions by exposing private internal fields directly.
    4. D.Composition avoids heap allocations by embedding the delegate object directly into the caller's stack frame.
    Show answer

    B. Composition allows behaviors to be swapped dynamically at runtime and avoids tightly coupling internal implementation details.

    Favoring composition over inheritance reduces white-box reuse where subclasses rely on internal superclass details. It also allows delegates to be swapped at runtime.
  4. Question 4 · Advanced · SOLID

    According to the Liskov Substitution Principle (LSP) formalized by Liskov and Wing, how must a subtype's method contracts relate to the supertype's contracts?
    1. A.Subtypes may strengthen preconditions and weaken postconditions.
    2. B.Subtypes must maintain identical preconditions and identical postconditions.
    3. C.Subtypes may weaken preconditions and strengthen postconditions.
    4. D.Subtypes may broaden the set of thrown checked exceptions.
    Show answer

    C. Subtypes may weaken preconditions and strengthen postconditions.

    LSP requires behavioral subtyping: preconditions cannot be strengthened (subtype must accept at least everything the supertype accepted), and postconditions cannot be weakened (subtype must guarantee at least what the supertype guaranteed).

How scoring and certificates work

  • Each check has 15 multiple-choice questions with one correct answer, and one timer for the whole check. A question you leave unanswered scores nothing.
  • Practice is free without an account and shows whether each answer is right as you go, with an explanation.
  • The certified exam is scored when you submit. 60% passes, which is 9 of 15. Easy unlocks Moderate, and Moderate unlocks Advanced.
  • Passing the exam while signed in earns a free certificate, valid for one year, with its own verification page. See a sample certificate.