Bird
0
0

Which Java code snippet correctly demonstrates polymorphism through method overriding?

easy📝 Syntax Q3 of 15
Java - Polymorphism
Which Java code snippet correctly demonstrates polymorphism through method overriding?
Aclass Vehicle { void move() { System.out.println("Moving"); } } class Car extends Vehicle { void move(int speed) { System.out.println("Car moving at " + speed); } }
Bclass Vehicle { void move() { System.out.println("Moving"); } } class Car extends Vehicle { void move() { System.out.println("Car moving"); } }
Cclass Vehicle { void move() { System.out.println("Moving"); } } class Car extends Vehicle { void move() { System.out.println("Moving"); } void move(int speed) {} }
Dclass Vehicle { void move() { System.out.println("Moving"); } } class Car { void move() { System.out.println("Car moving"); } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand method overriding

    Overriding means subclass provides a specific implementation of a method declared in superclass with the same signature.
  2. Step 2: Analyze options

    class Vehicle { void move() { System.out.println("Moving"); } } class Car extends Vehicle { void move() { System.out.println("Car moving"); } } shows subclass Car overriding move() method correctly.
  3. Final Answer:

    class Vehicle { void move() { System.out.println("Moving"); } } class Car extends Vehicle { void move() { System.out.println("Car moving"); } } demonstrates correct polymorphism via method overriding.
  4. Quick Check:

    Same method signature overridden in subclass [OK]
Quick Trick: Same method signature overridden in subclass [OK]
Common Mistakes:
  • Confusing method overloading with overriding
  • Missing same method signature in subclass
  • Not extending superclass properly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes