Bird
Raised Fist0

Given this code:

medium📝 Predict Output Q5 of Q15
C Sharp (C#) - Inheritance
Given this code:
class Vehicle { public string Move() => "Moving"; } class Car : Vehicle { } class Program { static void Main() { Car c = new Car(); System.Console.WriteLine(c.Move()); } }
What is the output?
ARuntime error
BMoving
CCompile error
DCar
Step-by-Step Solution
Solution:
  1. Step 1: Check inheritance and method availability

    Car inherits from Vehicle and does not override Move(), so it uses Vehicle's Move().
  2. Step 2: Determine output of Move()

    Move() returns "Moving", so that is printed.
  3. Final Answer:

    Moving -> Option B
  4. Quick Check:

    Inherited method output = Moving [OK]
Quick Trick: Inherited methods are accessible unless overridden [OK]
Common Mistakes:
MISTAKES
  • Expecting class name as output
  • Thinking method is missing in derived class
  • Confusing compile errors with inheritance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes