Free Practice Quiz Question List

10 Inheritance and Polymorphism Online Quiz Questions

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

20 questions
01
Choose one
1 point

Which Java keyword declares that one class is a subclass of another class?

  1. A

    inherits

  2. B

    extends

  3. C

    super

  4. D

    instanceof

02
Choose one
1 point

Given an Animal constructor declared as Animal(String name), which statement should a Dog constructor use to initialize the inherited name state?

  1. A

    this(name)

  2. B

    extends(name)

  3. C

    super(name)

  4. D

    parent(name)

03
Choose one
1 point

A subclass is intended to replace an inherited instance method, but the programmer might accidentally write a mismatched parameter list. Which annotation best helps detect that mistake?

  1. A

    @Override

  2. B

    @Inherited

  3. C

    @Super

  4. D

    @Polymorphic

04
Choose all
1 point

Which two statements correctly distinguish method overriding from method overloading in Java? Select all that apply.

  1. A

    Overriding supplies a subclass implementation for inherited behavior.

  2. B

    Overloading requires a superclass-subclass relationship.

  3. C

    Overloading can use different parameter lists for the same method name.

  4. D

    Overriding is created merely by changing a method's parameter type.

05
Choose all
1 point

Assume Dog and Cat both extend Animal and override makeSound(). Which two statements accurately describe this code?

  1. A

    Animal a = new Dog(); is valid when Dog extends Animal.

  2. B

    The declared type alone determines which overridden instance method runs.

  3. C

    A call through an Animal reference can execute Dog's override when the object is a Dog.

  4. D

    A separate if statement for every subclass is required for dynamic dispatch.

06
True or false
1 point

True or false: In Java, constructors are inherited from a superclass in the same way that accessible methods can be inherited.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: A static method in a subclass participates in the same runtime overriding and dynamic dispatch mechanism as an instance method.

  1. A

    True

  2. B

    False

08
Written response
1 point

What Java concept describes selecting an overridden instance method according to the runtime type of the object rather than the declared type of the reference?

09
Written response
1 point

What short relationship phrase describes the connection between a Car and an Engine when the Car contains and delegates to an Engine?

10
Fill in the blank
1 point

Complete the statement: In an inheritance relationship, the existing general class is the , and the more specific class is the .

11
Fill in the blank
1 point

Complete the statement: A(n) cannot be instantiated directly and may require subclasses to implement its .

12
Open ended
1 point

A developer wants to make Car extend Engine solely to reuse Engine.start(), while another developer wants Dog to extend Animal and override makeSound(). Explain which design is appropriate in each case and justify the choice using the is-a, has-a, substitutability, and code-reuse principles.

13
Choose one
1 point

Which statement best describes the purpose of an abstract superclass such as Shape in the material?

  1. A

    It can be instantiated only when all methods are static.

  2. B

    It can define common structure while preventing direct instantiation.

  3. C

    It must contain only private fields and no methods.

  4. D

    It automatically converts every subclass reference into a superclass object.

14
Written response
1 point

Complete the Java declaration for a Dog subclass of Animal: class Dog ____ Animal { }

15
Choose one
1 point

A Car needs an Engine object to perform its starting behavior, but a car is not a kind of engine. Which design best represents this relationship?

  1. A

    Declare Car as a subclass of Engine

  2. B

    Give Car an Engine field and delegate engine operations to it

  3. C

    Make Engine extend Car

  4. D

    Use downcasting whenever the car starts

16
Choose one
1 point

Consider Parent.display(int value) and Child.display(String value). What is the relationship of the Child method to the Parent method?

  1. A

    The child method overrides the parent method

  2. B

    The child method hides a static method

  3. C

    The child method overloads the parent method

  4. D

    The child method is an abstract implementation

17
Choose one
1 point

Given Animal animal = new Dog(); where Dog overrides makeSound() to print Woof, what does animal.makeSound() print?

  1. A

    Some animal sound

  2. B

    Woof

  3. C

    Meow

  4. D

    The code does not compile because the reference type is Animal

18
Written response
1 point

What is the Java behavior called when an overridden instance method is selected according to the object's runtime type rather than its reference type?

19
Choose one
1 point

Given Animal animal = new Dog();, and assuming bark() is declared only in Dog, what happens if the program tries to call animal.bark() directly?

  1. A

    animal.bark() is not directly available through the Animal reference

  2. B

    animal.bark() always calls the Dog implementation automatically

  3. C

    The reference must be changed to Object before calling bark()

  4. D

    A superclass reference automatically gains every subclass-specific method

20
True or false
1 point

True or false: If Animal animal = new Cat();, casting animal directly to Dog is safe because both Dog and Cat are subclasses of Animal.

  1. A

    True

  2. B

    False