OOP Concepts MCQ questions
Take a short practice test with instant feedback, then revise every question with its answer and the reason behind it.
- Questions
- 124
- From lessons
- 104
- Your last test
- —
Practice test
Depending on interfaces makes it easy to use fake implementations in unit tests.
All questions with answers
Which OOP principle hides internal state behind methods?
Show answer
Answer: B. Encapsulation
Encapsulation keeps data private and exposes controlled operations.
An object is…
Show answer
Answer: B. An instance of a class
The class is the blueprint; each object is a concrete instance.
Which relationship does inheritance represent?
Show answer
Answer: B. is-a
A Dog is an Animal. Composition is has-a.
Which feature lets one interface have many implementations called the same way?
Show answer
Answer: B. Polymorphism
Polymorphism lets code call shape.Area() without knowing the concrete shape.
Method overloading is resolved…
Show answer
Answer: B. At compile time
The compiler picks the overload from the argument types.
Which can you NOT instantiate directly?
Show answer
Answer: B. An abstract class
Abstract classes are meant to be inherited.
How many classes can a C# class inherit from?
Show answer
Answer: A. One
C# supports single class inheritance but multiple interfaces.
Which access modifier allows access from subclasses only (plus the class itself)?
Show answer
Answer: C. protected
protected members are visible to the class and derived classes.
What does the S in SOLID stand for?
Show answer
Answer: B. Single Responsibility
A class should have one reason to change.
Which principle says subtypes must be usable in place of their base type?
Show answer
Answer: B. Liskov Substitution
Derived classes must honour the base class’s contract.
Which pattern ensures a class has only one instance?
Show answer
Answer: B. Singleton
In modern apps a DI container’s singleton lifetime is usually preferred.
Which pattern swaps an algorithm at runtime through a common interface?
Show answer
Answer: A. Strategy
For example different IShippingCalculator implementations.
Which pattern notifies subscribers when state changes?
Show answer
Answer: A. Observer
Events and pub/sub systems are observers.
What is wrong with this design?
C# Illustrative public class ReportService { private readonly SmtpEmailSender _email = new SmtpEmailSender("smtp.example.com"); }Show answer
Answer: B. ReportService creates its own dependency, so it cannot be tested with a fake
Inject an IEmailSender instead of calling new inside the class.
In composition, the part’s lifetime…
Show answer
Answer: B. Depends on the whole
An OrderLine does not exist without its Order.
Which keyword lets a C# subclass replace a virtual method?
Show answer
Answer: B. override
override replaces the implementation polymorphically; new only hides it.
An interface in C# can contain…
Show answer
Answer: C. Method signatures (and default implementations)
Interfaces describe members; C# 8+ allows default implementations but not instance fields.
What does a constructor return?
Show answer
Answer: B. The class type implicitly — it initialises the new object
Constructors have no declared return type; new returns the created object.
Which UML symbol marks a private member?
Show answer
Answer: B. -
+ public, - private, # protected, ~ package/internal.
“Favour composition over inheritance” mainly improves…
Show answer
Answer: B. Flexibility and loose coupling
Behaviour can be combined and swapped without deep hierarchies.
What is the relationship between a class and an object?
Show answer
Answer: C. A class is a blueprint; an object is an instance of it
Classes describe structure and behaviour; objects are concrete instances created from them.
From the lesson: Classes and ObjectsWhat is logged?
JavaScript Illustrative class Counter { constructor() { this.n = 0; } inc() { this.n++; } } const a = new Counter(); const b = new Counter(); a.inc(); a.inc(); b.inc(); console.log(a.n, b.n);Show answer
Answer: B. 2 1
Each object has its own n. a was incremented twice, b once.
From the lesson: Classes and ObjectsWhat is the main goal of encapsulation?
Show answer
Answer: B. Hide internal state and control how it changes
Encapsulation protects an object’s internal data and only allows changes through controlled methods.
From the lesson: EncapsulationIn JavaScript, a field declared as #secret can be read from outside the class with obj.#secret.
Show answer
Answer: B. False
Private fields are only accessible inside the class body; outside access is a syntax error.
From the lesson: EncapsulationWhat is logged?
JavaScript Illustrative class Wallet { #money = 100; get money() { return this.#money; } } console.log(Object.keys(new Wallet()));Show answer
Answer: B. []
Private fields are not properties, and the getter lives on the prototype, so the object has no own keys.
From the lesson: Encapsulation