Courseiva
Object-Oriented ProgrammingmediumMultiple ChoiceObjective-mapped

1Z0-811 Polymorphism Practice Question

Exhibit

public class Vehicle { protected int speed; public Vehicle() { speed = 0; } public void accelerate() { speed += 10; } } public class Car extends Vehicle { public void accelerate() { speed += 20; } }

Refer to the exhibit. What is the output when the following code is executed? Vehicle v = new Car(); v.accelerate(); System.out.println(v.speed);

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

20

The code uses polymorphism: the reference variable v of type Vehicle points to a Car object. Since accelerate() is overridden in Car, the overridden method is invoked, adding 20 to the speed instance variable inherited from Vehicle. The protected field speed is accessible in the subclass. Therefore, after calling v.accelerate(), speed becomes 20. Option D is correct.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 10

    Why it's wrong here

    Incorrect because the Vehicle's accelerate method is not called due to dynamic binding; Car's overridden method adds 20, not 10.

  • 0

    Why it's wrong here

    Incorrect because speed is modified by the accelerate method; it does not remain 0.

  • Compilation error

    Why it's wrong here

    Incorrect because the code compiles successfully: Vehicle has the accelerate method and speed is accessible.

  • 20

    Why this is correct

    Correct because the Car's overridden accelerate method adds 20 to speed, resulting in 20.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.