What are the four pillars of OOP in C#?
public abstract class Shape { public abstract double Area(); }
public class Square(double s) : Shape { public override double Area() => s*s; }6 OOP interview questions for C# roles, each with a model answer, examples and likely follow-ups.
6 questionsWhat are the four pillars of OOP in C#?
public abstract class Shape { public abstract double Area(); }
public class Square(double s) : Shape { public override double Area() => s*s; }How do properties provide encapsulation?
public int Age { get; private set; }
public decimal Discount { get => _d; set => _d = Math.Clamp(value,0,100); }What is the difference between overriding and hiding (override vs new)?
class B { public virtual void Go()=>Console.Write("B"); }
class D : B { public override void Go()=>Console.Write("D"); }What does the sealed keyword do and why use it?
public sealed class Logger { }What is composition over inheritance and when do you prefer it?
class Car { private readonly Engine _engine; public Car(Engine e)=>_engine=e; }How do virtual method tables enable polymorphism, and what is the cost?
Shape s = new Square(3);
double a = s.Area(); // resolved to Square.Area at run time