Easy csharp

Inheritance — Animal and Dog

Problem

Create base class Animal with Speak() and override in Dog.

Hints
  • override Speak in Dog

Your practice code

Ready — edit the code above and click Run.

Solution

using System;

class Animal { public virtual void Speak() => Console.WriteLine("Some sound"); }
class Dog : Animal { public override void Speak() => Console.WriteLine("Bark"); }
class Program { static void Main() { new Dog().Speak(); } }

Try solving on your own first, then reveal the official answer.

Explanation

virtual/override enable polymorphism—core OOP interview concept.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details