thecodingcompany
Technical MCQ

OOP & Design

Encapsulation, inheritance, polymorphism, SOLID and design patterns.

Questions6
FormatMCQ + explanation

6 questions

Answer each one before scrolling to the solution. The explanation names the mechanism, not just the choice.

01Method overloading is an example of:
  1. A.Runtime polymorphism
  2. B.Compile-time polymorphism
  3. C.Encapsulation
  4. D.Abstraction
Answer. Overloading is resolved by the compiler based on the method signature, so it is compile-time (static) polymorphism.
02The Liskov Substitution Principle states that:
  1. A.Classes should be open for extension but closed for modification
  2. B.Subtypes must be usable wherever their base type is expected
  3. C.An object should have only one reason to change
  4. D.Depend on abstractions, not concretions
Answer. LSP requires a derived class to honour the contract of its base class, so substituting it never breaks the caller.
03Which pattern ensures a class has only one instance with a global access point?
  1. A.Factory
  2. B.Observer
  3. C.Singleton
  4. D.Decorator
Answer. The Singleton pattern controls instantiation so exactly one object exists, usually via a private constructor and a static accessor.
04Encapsulation is best described as:
  1. A.Inheriting behaviour from a parent
  2. B.Hiding internal state and exposing a controlled interface
  3. C.Having many forms of a method
  4. D.Splitting a program into modules
Answer. Encapsulation bundles data with the methods that operate on it and restricts direct external access to internal state.
05Composition is often preferred over inheritance because:
  1. A.It runs faster
  2. B.It avoids tight coupling and fragile base-class problems
  3. C.It uses less memory
  4. D.It is required by compilers
Answer. Composition lets behaviour be assembled at runtime and avoids the rigid, breakage-prone hierarchies inheritance creates.
06An abstract class differs from an interface in that it:
  1. A.Cannot have methods
  2. B.Can contain state and concrete methods
  3. C.Cannot be extended
  4. D.Has no constructor
Answer. An abstract class may hold fields, constructors and implemented methods, whereas a traditional interface defines only a contract.

Practise here. Get placed there.

Prep+ is unlimited practice. When you are ready to turn it into an offer, TCC Placement Partner handles portfolio, resume and interviews.