Abstract Shape with Circle and Rectangle overriding Area().
Toolliyo Coach
Progressive help: Nudge → Guide → Approach. Full solution stays behind the Solution tab.
Editor is open — no login wall to practice.
| Test | Status | Details |
|---|
Ready — edit the code above and click Run or Submit.
using System;
abstract class Shape { public abstract double Area(); }
class Circle : Shape {
double _r;
public Circle(double r) => _r = r;
public override double Area() => Math.PI * _r * _r;
}
class Rectangle : Shape {
double _w, _h;
public Rectangle(double w, double h) { _w = w; _h = h; }
public override double Area() => _w * _h;
}
class Program {
static void Main() {
Shape[] shapes = { new Circle(2), new Rectangle(3, 4) };
foreach (var s in shapes) Console.WriteLine(s.Area());
}
}
Prefer Coach (Nudge → Guide → Approach) before revealing. No forced signup.
Runtime polymorphism via abstract base + override—expect this in .NET OOP interviews.
Sign in to save and review your submission history. You can still Run code on the Editor tab as a guest.
Sign in