C# Interview Questions: Object-Oriented Programming, Inheritance and Design
Reviewed by Mark Dickie · Last updated
3 questions on this page you can answer and see marked on the spot. Go to the first one
C# is a statically typed, object-oriented language on the .NET runtime, and interviewers use its class model to see how you design code. Expect questions on encapsulation, inheritance, polymorphism and abstraction, plus the C# features that change those rules, such as interfaces with default methods and records. Answers tend to stumble on method hiding versus overriding and on when an abstract class is the better choice than an interface.
Which C# object-oriented topics come up in interviews?
| Topic | What the interviewer checks | Common mistake |
|---|---|---|
virtual, override, new | Which method runs when a base-typed reference holds a derived object | Expecting new to behave like override. It only hides the member, so a base-typed reference still calls the base version. |
Abstract class vs interface | When to keep state and constructors, versus a contract that can carry default methods (C# 8 and later) | Adding a member to a published interface breaks every class that implements it. |
sealed and readonly | Which types can be subclassed and which fields can change after construction | Assuming readonly makes an object immutable. It only fixes the reference; the object's own fields can still change. |
IDisposable and using | How cleanup runs when the body or the constructor throws | Assuming a constructor that throws will call Dispose. The object never finishes construction, so the constructor must release what it already acquired. |
record types | Value equality and with copies, versus reference identity | A record class still holds reference-type members, so a copy made with with shares them. |
How should you practice C# object-oriented questions?
- Write a
Shapebase class with avirtualArea()method, call it through aShapevariable on a derived object, then change the base method tonewand compare the output. - Implement
IEquatable<T>on aMoneystruct, then check thatEqualsandGetHashCodereturn consistent results for equal values. - Put an
IDisposableclass inside ausingblock, throw an exception in the block, and confirmDisposestill runs. - Convert a
classwith three properties to arecord, then list which equality, copy andToStringbehaviour changed.
Key facts
- Tarmac has 14 C# interview questions on this topic, 10 of them on this page, at difficulty 1–5 of 5.
- Tarmac tracked 871 job postings asking for C# in November 2026.
- Roles asking for C# advertise a median base salary of £70,000, across 342 job postings as of November 2026.
- Tarmac last reviewed these C# interview questions on 3 December 2026.
At a glance
| Questions | 10 shown · 14 in the bank |
|---|---|
| Difficulty | 1–5 of 5 |
| Formats | Multiple choice, Short answer, Fill in the blank, Code output, True / false |
What you'll review
- interfaces and abstract classes
- classes and objects
- inheritance and polymorphism csharp
Practice questions
Try one before you open the answer. Pick an option and press Check; it's marked on the spot.
In C#, which statement about inheritance from interfaces and abstract classes is correct?#
Options
Show answer
In C#, a class can implement multiple interfaces but can inherit from only one abstract class. C# allows single inheritance of implementation, so a class has just one base class, while interfaces are contracts that any number of classes can implement.
C# supports single inheritance of implementation, so a class may have only one base class, whether abstract or not. Interfaces are contracts rather than base classes, and a single class or struct may implement any number of them. The statement about implementing multiple interfaces while inheriting from one abstract class is therefore the correct one. The statement about inheriting from several abstract classes is wrong because of single base-class inheritance, and the one about interface instance fields is wrong because interfaces cannot declare instance fields.
In C#, what does the new keyword do when used with a class name, as in var obj = new MyClass();?#
Show answer
It allocates memory for the new object on the managed heap, then invokes a matching constructor to initialize its fields, and returns a reference to that object.
In C#, new MyClass() allocates memory on the managed heap for a new instance, then calls the appropriate constructor to initialize the object's fields. The expression evaluates to a reference to that instance, which is assigned to obj. Declaring a variable alone would not create an object, so the new expression is what performs the allocation and initialization.
In C#, the _____ keyword is used in a derived class to replace the implementation of a method declared with the virtual keyword in its base class.#
Show answer
In C#, the override keyword is used in a derived class to replace the implementation of a method declared with the virtual keyword in its base class.
The override keyword in a derived class replaces the implementation of a method declared with virtual in the base class. Because the call is dispatched at runtime to the most-derived override, this enables runtime polymorphism. The new keyword, by contrast, hides a base member rather than replacing it virtually.
Consider the following C# code:#
Show answer
The program prints 5. The variable obj is declared as type Base but is assigned an instance of Derived. Because GetValue is marked virtual in Base and overridden with the override keyword in Derived, the runtime uses the actual object type (Derived) to choose the implementation at call time. So obj.GetValue() invokes Derived.GetValue(), which returns 5, and Console.WriteLine prints 5.
obj has the compile-time type Base but holds a new Derived() instance. Because GetValue is declared virtual in Base and replaced with override in Derived, the call obj.GetValue() is resolved at runtime through the object's actual type, so Derived.GetValue runs and returns 5, which Console.WriteLine prints. If Derived used new instead of override (method hiding), the compile-time type Base would decide the call and the program would print 3.
Consider the following C# code. What is printed to the console when the program runs?#
using System;
class Base
{
public virtual int GetValue() { return 1; }
}
class Derived : Base
{
public override int GetValue() { return 3; }
}
class Program
{
static void Main()
{
Base obj = new Derived();
Console.WriteLine(obj.GetValue());
}
}Show answer
3
The variable obj has compile-time type Base but runtime type Derived. Because GetValue is declared virtual in Base and override in Derived, the CLR uses runtime polymorphic dispatch and calls Derived.GetValue(), which returns 3, so that value is printed.
In C#, an abstract class can be instantiated directly using the new keyword.#
Options
Show answer
False. In C#, an abstract class cannot be instantiated directly with new; the compiler reports error CS0144. You must create a concrete, non-abstract subclass that inherits from it and instantiate that subclass instead.
The abstract modifier on a class prevents direct instantiation. Writing new on an abstract class is rejected by the compiler with error CS0144 ('Cannot create an instance of the abstract class or interface'). To create an object, you must derive a concrete (non-abstract) class from the abstract class and instantiate that derived class. The statement is therefore false.
In C#, if a class defines a constructor that takes parameters but does not define an explicit parameterless constructor, the compiler will still automatically generate a default parameterless constructor.#
Options
Show answer
A C# class that declares a parameterized constructor does not receive an implicit parameterless constructor. The compiler generates one only when a class declares no constructors, so new MyClass() fails with error CS1729 unless a parameterless constructor is written explicitly.
False. The C# compiler generates an implicit parameterless constructor only when a class declares no constructors at all. Once any constructor is written, whether parameterized or not, that automatic generation stops. Code such as new MyClass() then fails with compile error CS1729 ('MyClass' does not contain a constructor that takes 0 arguments) unless a parameterless constructor is declared explicitly. This commonly breaks existing code when a parameterized constructor is added to a class that previously relied on the implicit one.
The following C# class fails to compile:#
Show answer
The Increment method is declared static, but it tries to access the instance field count. Static methods do not have access to instance members because they operate at the class level, not on a specific object instance. To fix this, either make Increment an instance method (remove static) or make count a static field so it belongs to the class rather than individual instances.
The Increment method is declared static, but it attempts to read and modify count, which is an instance field. In C#, static methods belong to the class itself, not to any particular instance, so they cannot access instance members without an object reference. This produces compile error CS0120: 'An object reference is required for the non-static field, method, or property Counter.count'. The fix is either to remove static from Increment (making it an instance method) or to make count a static field.
What does the following C# program print to the console when compiled and run? Trace the output exactly as it would appear, line by line.#
using System; // C# 12 / .NET 8 (dotnet run console app, all code in one file, trimmed for brevity) --- code start --- class Base { public virtual void Show() => Console.WriteLine( Base.Show ); public virtual void Display() { Console.WriteLine( Base.Display ); Show(); } } class Derived : Base { public override void Show() => Console.WriteLine( Derived.Show ); public new void Display() { Console.WriteLine( Derived.Display ); Show(); } } class Program { static void Main() { Base b = new Derived(); b.Display(); } } --- code end ---Show answer
Base.Display\nDerived.Show
The variable b is declared as Base and assigned a Derived instance. Display is declared virtual in Base, but Derived re-declares it with new (method hiding), not override. Because Derived.Display merely hides rather than overrides, the compiler's view of b as type Base causes b.Display() to resolve to Base.Display. Inside Base.Display, the call to Show() is virtual, and Derived does override Show, so runtime dispatch selects Derived.Show. The output is therefore Base.Display on the first line followed by Derived.Show on the second.
Consider the following C# program that calls a virtual method from a base constructor. What exact output does it print to the console when new Derived(99) is executed in Main? Give the lines in the order they are printed.#
using System;
class Base
{
public Base()
{
Console.WriteLine("Base ctor");
Initialize();
}
public virtual void Initialize() { }
}
class Derived : Base
{
private int _value;
public Derived(int value)
{
_value = value;
Console.WriteLine("Derived ctor");
}
public override void Initialize()
{
Console.WriteLine($"Derived.Initialize: value={_value}");
}
}
class Program
{
static void Main()
{
new Derived(99);
}
}Show answer
Base ctor
Derived.Initialize: value=0
Derived ctor
When new Derived(99) runs, the CLR allocates the object and zero-initializes all fields, so _value is 0. The derived constructor is invoked, but before its body executes the base constructor must run. Base's constructor prints Base ctor and then calls Initialize(). Because the call is virtual, the CLR dispatches to the most-derived override, Derived.Initialize, even though Derived's constructor body has not yet run. So _value still holds its default 0 and the override prints Derived.Initialize: value=0. Only after the base constructor returns does Derived's constructor body execute: it assigns _value = 99 and prints Derived ctor. The key point is that virtual dispatch during construction reaches the derived override while the derived part of the object is only partially constructed.
Related interview questions
Job market
See csharp salaries and hiring demand from live job postings.
The other 4 questions
This page shows 10 and marks what you pick. That's as far as a page can go. A free account opens the other 4 and keeps every answer. What you miss comes back until it's right: after a day, then at longer gaps.
Free · the whole bank · 100 answers per 30 days, each marked with written feedback