Free Practice Quiz Question List

4 Inheritance Online Quiz Questions

Use this free practice quiz with 20 questions to review 4 Inheritance, test your knowledge, and prepare for your next test or exam.

20 questions
01
True or false
1 point

True or false: If MountainBike derives from Bicycle, and Bicycle derives from Vehicle, then MountainBike also has inherited behavior from Vehicle.

  1. A

    True

  2. B

    False

02
True or false
1 point

True or false: Constructors are generally inherited by a derived class in the same way as ordinary inherited methods.

  1. A

    True

  2. B

    False

03
Choose one
1 point

Which statement best describes the relationship between Bicycle and Vehicle when Bicycle derives from Vehicle?

  1. A

    A Bicycle contains a Vehicle and should never inherit from it.

  2. B

    A Bicycle is a specialized kind of Vehicle.

  3. C

    A Vehicle must always be implemented as an interface.

  4. D

    A Bicycle and a Vehicle are unrelated because they have different fields.

04
Choose all
1 point

Which two are valid benefits or capabilities of a well-designed inheritance relationship? Select all correct choices.

  1. A

    It guarantees that changes to the base class cannot affect derived classes.

  2. B

    It can place shared fields and methods in one base implementation.

  3. C

    It prevents derived classes from adding specialized behavior.

  4. D

    It allows derived objects to be used where the base type is expected.

05
Fill in the blank
1 point

Complete the definitions: The existing general class is the , while the new specialized class is the .

06
Fill in the blank
1 point

Complete the comparison: Replacing inherited behavior in a derived class is called , whereas creating methods with the same name but different parameter lists is called .

07
Choose one
1 point

A program stores Dog and Cat objects in a collection of Animal references and calls speak() on each reference. Which design benefit does this demonstrate?

  1. A

    A method can process Animal references while each object's runtime type selects its speak() implementation.

  2. B

    A method must use instanceof checks for every possible animal before calling speak().

  3. C

    A base-type reference can invoke only methods declared directly in the concrete subclass.

  4. D

    Polymorphism requires every derived class to have a separate collection-processing method.

08
Choose all
1 point

Which two design practices support a sound inheritance hierarchy? Select all correct choices.

  1. A

    The base class should represent stable behavior common to all derived classes.

  2. B

    A base class should contain any behavior that could possibly be reused once.

  3. C

    Derived types should satisfy the behavioral expectations of the base type.

  4. D

    A hierarchy is appropriate whenever two classes have fields with similar names.

09
Choose one
1 point

What is a significant risk of a deep inheritance hierarchy such as Object → Vehicle → Bicycle → MountainBike → RacingMountainBike?

  1. A

    It ensures that all subclasses have unrelated responsibilities.

  2. B

    It eliminates dependencies between ancestors and descendants.

  3. C

    It can make behavior difficult to trace across multiple ancestor levels.

  4. D

    It guarantees that every inherited method has exactly one implementation.

10
True or false
1 point

True or false: A derived class overrides a method by defining another method with the same name but a different parameter list.

  1. A

    True

  2. B

    False

11
Choose one
1 point

A system needs to represent many car models that differ only by values such as make and model, not by meaningful behavior. Which design is generally most appropriate?

  1. A

    Create a subclass for every possible combination of make and model.

  2. B

    Use inheritance because all cars must have exactly the same implementation.

  3. C

    Represent the changing distinction with data values such as make and model.

  4. D

    Avoid storing make or model because inheritance cannot represent any variation.

12
Open ended
1 point

Explain when inheritance is preferable to composition in object-oriented design. Include the role of the is-a relationship, the base-class contract, and one example showing why the alternative design would be appropriate.

13
Choose one
1 point

In the example hierarchy, which statement best describes the relationship between Bicycle and Vehicle?

  1. A

    Vehicle is a specialized kind of Bicycle.

  2. B

    Bicycle is a specialized kind of Vehicle.

  3. C

    Bicycle and Vehicle are unrelated classes.

  4. D

    Vehicle contains a Bicycle as one of its private fields.

14
Choose one
1 point

A Car needs an Engine to start, but a car is not a kind of engine. Which design choice is generally most appropriate?

  1. A

    Inheritance, because every class should reuse another class.

  2. B

    Inheritance, because Car and Engine are both concrete classes.

  3. C

    Composition, because Car uses an Engine without being a kind of Engine.

  4. D

    No relationship, because objects cannot collaborate.

15
Choose one
1 point

Given Animal animal = new Dog();, what happens when animal.speak() is called if Dog overrides speak()?

  1. A

    The call always uses Animal's method because the variable is declared as Animal.

  2. B

    The call fails because an Animal reference cannot refer to a Dog.

  3. C

    The call uses Dog's implementation of speak.

  4. D

    The call uses a randomly selected implementation.

16
Written response
1 point

What is the technical term for a derived class providing a replacement implementation of an inherited instance method with a compatible signature?

17
Choose one
1 point

Which statement best explains constructor behavior when a derived class introduces its own state?

  1. A

    The derived class must use the base constructor automatically and cannot initialize its own state.

  2. B

    The derived class has its own constructor responsibilities and may invoke a base-class constructor.

  3. C

    The base constructor is copied into the derived class as an inherited method.

  4. D

    Constructors are irrelevant because inherited fields initialize themselves.

18
Written response
1 point

Which Java keyword can an overriding method use to call the base implementation before adding derived-class behavior?

19
Written response
1 point

A Java base class declares an abstract method and does not provide an implementation for that method. What kind of class must the base class be?

20
Written response
1 point

A base class declares the abstract method double area(). A derived class Circle is intended to be concrete rather than abstract. What must Circle do with area()?