OOP Expert

1 / 89

Explain the conceptual difference between a class and an object. If a class is a blueprint, what exactly is the instance in memory?

Select the correct answer

1

A cached compiled copy of the class definition shared across every running instance

2

A reserved name in the symbol table pointing back at the original class template

3

A concrete allocation of memory holding actual field values described by the class

4

A duplicate of the class source code that is reparsed each time it is called

What is the 'this' (or 'self') reference conceptually, and how does an object know its own context?

Select the correct answer

1

A static handle shared by all instances that references the class definition

2

A copy of the object's fields passed by value into each method invocation

3

An implicit reference to the current instance so methods act on its own data

4

A global pointer to the most recently created object of any class type

What is the difference between a Class and an Object in terms of memory allocation?

Select the correct answer

1

Both a class and an object reserve equal memory whenever either of them is used.

2

An object is a blueprint needing no memory; a class reserves memory upon creation.

3

A class reserves memory when defined; each object merely references that shared block.

4

A class is a blueprint allocating no memory; an object reserves memory once instantiated.

How does the lifecycle of an object work, and explain the concept of garbage collection or manual destruction at a high level?

Select the correct answer

1

It is duplicated on each access and every old copy must be freed by the caller

2

It exists forever from program start and is only cleared at final process exit

3

It is created, used, then reclaimed automatically or freed manually when unreferenced

4

It is destroyed instantly the moment any single method finishes running on it

Can you have an object without a class?

Select the correct answer

1

Yes, but only when the object contains no methods and holds pure data

2

Yes, prototype-based languages create objects directly from other objects

3

No, every object universally requires a compiled class declaration first

4

No, unless the runtime silently generates a hidden anonymous class for it

What happens conceptually during Object Instantiation?

Select the correct answer

1

All existing instances are copied together into one new merged object

2

A shared static template is renamed and exposed directly to the caller

3

Memory is allocated, fields are initialized, and a reference is returned

4

The class source is recompiled and its bytecode is reloaded into memory

What is the 'Root Object' concept (e.g., Object class) found in many OO languages?

Select the correct answer

1

The first instance created at startup that every later object must reference

2

The entry class whose main method runs before any other object exists

3

A base type all classes implicitly inherit, providing common shared methods

4

A special container holding one global copy of every class in the program

Explain the difference between state, behavior, and identity of an object.

Select the correct answer

1

State is its data, behavior is its methods, identity is its unique existence

2

State is its methods, behavior is its data, identity is its memory alignment

3

State is its class name, behavior is its parent, identity is its field count

4

State is its address, behavior is its type, identity is its stored values

Explain the order of initialization when an object is instantiated.

Select the correct answer

1

Superclass constructor runs first, then field initializers, then the constructor body

2

Field initializers run first, then the constructor body, then the superclass constructor

3

The superclass and subclass constructors run together, then all field values are set

4

The constructor body runs first, then field initializers, then the superclass setup

How does Object-Oriented Programming differ from procedural or structured programming, and what specific problems does it solve?

Select the correct answer

1

OOP and procedural are identical except that OOP forbids the use of any global variables.

2

OOP bundles data with behavior into objects, taming complexity that procedural code scatters.

3

OOP separates data from functions completely, unlike procedural code which merges them tightly.

4

OOP replaces functions with loops entirely, solving the memory problems procedural code creates.

Explain the four pillars of OOP to a non-technical stakeholder.

Select the correct answer

1

Write threads that run concurrently, lock resources, share memory, and synchronize on events.

2

Hide details, build on existing things, treat similar things alike, and group related data.

3

Store data in tables, query with joins, index the columns, and normalize to avoid duplication.

4

Break work into functions, pass arguments, return values, and avoid using any global state.

What are the primary goals of OOP, and how does it improve modularity, reusability, and maintainability in a large-scale codebase?

Select the correct answer

1

It forces all code into a single class so the whole system stays tightly connected together.

2

It removes interfaces entirely, exposing internal state so modules can share data freely.

3

It duplicates logic across classes to guarantee that each module stays fully independent.

4

It encapsulates state behind interfaces, letting components be reused and changed independently.

Explain the concept of 'Message Passing' in OOP.

Select the correct answer

1

Objects directly modify each other's fields, bypassing methods to exchange internal data.

2

Messages are shared memory buffers that objects read from to synchronize their state.

3

Message passing means copying an entire object whenever another object needs its data.

4

Objects request behavior by sending messages, letting the receiver decide how to respond.

What are the common criticisms of the object-oriented paradigm?

Select the correct answer

1

Boilerplate, deep inheritance, and hidden mutable state can make behavior hard to trace.

2

It makes code impossible to reuse, since encapsulation prevents any sharing between classes.

3

It removes all abstraction, exposing implementation details that tightly couple every module.

4

It cannot model real-world entities, forcing developers to rely on global procedural state.

What are the trade-offs of using OOP, and in what scenarios might a different paradigm like functional or procedural be more effective?

Select the correct answer

1

Functional fits stateless transforms and concurrency; procedural fits simple linear scripts.

2

Functional fits mutable shared state, while procedural best models deep inheritance hierarchies.

3

OOP is always superior, so functional and procedural only suit very small teaching examples.

4

Procedural fits concurrency and immutability, whereas functional suits stateful object graphs.

What is the 'Message Passing' view of OOP versus the 'Method Call' view?

Select the correct answer

1

Message passing resolves everything at compile time, while method calls defer to runtime.

2

Method call implies late binding where the class picks the right message before compiling.

3

Message passing implies late binding where the object chooses its response at runtime.

4

Both views are identical since sending a message always compiles to a fixed function jump.

Why do we use getters and setters instead of making fields public, and what is the architectural benefit of this boilerplate?

Select the correct answer

1

They make every field accessible faster than direct access by caching computed values internally within the object.

2

They guarantee thread safety automatically so multiple threads can modify shared fields without any explicit locking.

3

They decouple the public interface from internal fields, allowing validation and later changes without breaking callers.

4

They reduce memory usage because private fields are only allocated lazily the first time they are actually accessed.

How does Encapsulation improve the security and maintainability of a system?

Select the correct answer

1

It duplicates data across many objects so that a single corrupted field cannot ever affect the rest of the system.

2

It restricts direct state access, enforcing invariants centrally and localizing the impact of internal changes.

3

It encrypts object fields at runtime so that external code can never read sensitive values directly from memory.

4

It removes the need for testing entirely since private fields cannot be modified incorrectly by any external code.

Explain the concept of Abstraction using a real-world example other than an ATM or a Car.

Select the correct answer

1

A TV remote creates many identical copies of itself so each room can independently control the same television.

2

A TV remote stores all its channel data privately so no other device can read the saved settings from it.

3

A TV remote lets you change channels by pressing a button without knowing the internal electronics behind it.

4

A TV remote inherits its buttons from a universal remote and overrides some of them for a specific brand.

What is the difference between data hiding and encapsulation: are they the same thing?

Select the correct answer

1

No; encapsulation bundles data with methods, while data hiding restricts external access to that internal data.

2

Yes; both terms mean exactly the same practice of grouping variables and functions together inside a class.

3

No; data hiding bundles behavior with state, while encapsulation only conceals the class name from its callers.

4

Yes; encapsulation is simply the modern name that has replaced the older deprecated term called data hiding.

What is the difference between Abstraction and Encapsulation? They both hide things, so why do we need both?

Select the correct answer

1

Abstraction bundles data with methods; encapsulation hides complexity behind a clean and simple interface.

2

Abstraction and encapsulation are identical concepts described using two different naming conventions in code.

3

Abstraction restricts access with keywords; encapsulation groups related classes together into logical packages.

4

Abstraction hides complexity to expose essential behavior; encapsulation bundles data and hides internal state.

Explain the conceptual difference between public, private, and protected access, and why is package-private or internal visibility useful in large systems?

Select the correct answer

1

public is visible within a package, private to subclasses, protected everywhere; internal exposes helper methods globally.

2

public is visible everywhere, private within the class, protected to subclasses; package-private hides module internals.

3

public is limited to the class, private to the module, protected to callers; package-private restricts inheritance chains.

4

public is open to subclasses, private to the package, protected within a file; internal keeps constructors fully hidden.

What is the difference between a static member and an instance member, and when is it appropriate to use a static method instead of an instance method?

Select the correct answer

1

Static members are created per instance and copied; use static methods only when overriding parent class behavior.

2

Static members belong to the class and are shared; use static methods when they need no instance state.

3

Static members belong to each object separately; use static methods when they must access private instance fields.

4

Static members exist only during construction; use static methods when an object requires polymorphic runtime dispatch.

What is an 'Inner Class' (or Nested Class), and when is it conceptually appropriate to use one?

Select the correct answer

1

A class instantiated statically; used when it must exist before the outer class object is ever created at runtime.

2

A class defined inside another; used when it is tightly bound to and only meaningful within the outer class.

3

A class that inherits from another; used when it must reuse and extend the outer class's public behavior.

4

A class shared across packages; used when many unrelated classes need access to the same reusable helper logic.

What is an anonymous class, and in what situations is it conceptually appropriate to use one?

Select the correct answer

1

A class created at runtime by reflection, ideal for dynamic plugin type loading.

2

A class with no fields or methods, ideal for marking a type without behavior.

3

A class hidden from other modules, ideal for keeping internal helpers private.

4

A class defined without a name and used once, ideal for quick one-off behavior.

What is the purpose of a sealed or final class, and when would you prevent a class from being extended?

Select the correct answer

1

To prevent modification so the class's fields become read-only after creation.

2

To prevent inheritance so the class's behavior and invariants stay guaranteed.

3

To prevent overriding so subclasses reuse but cannot alter any parent methods.

4

To prevent instantiation so the class can only expose static utility methods.

Can a class be both Abstract and Final? Why or why not?

Select the correct answer

1

No, since final requires all methods to be abstract and fully implemented.

2

No, since abstract demands subclassing while final blocks any subclass.

3

Yes, because final only stops method overriding, not class inheritance itself.

4

Yes, because abstract and final describe unrelated aspects of a class design.

What is name mangling, and what problem does it solve in the context of overloading or private members?

Select the correct answer

1

It rewrites private names with a class prefix to avoid subclass name clashes.

2

It merges duplicate method names into one entry to shrink the symbol table.

3

It renames overloaded methods so each signature maps to one unique symbol.

4

It encrypts private member names so external code can never reach them at all.

Explain the purpose of a Constructor. Can a Constructor be inherited or overridden?

Select the correct answer

1

It allocates memory for objects; it can be inherited but never overridden at all.

2

It initializes new objects; it is neither inherited nor overridden by subclasses.

3

It initializes new objects; it is inherited and may be overridden like any method.

4

It destroys unused objects; it is neither inherited nor overridden by subclasses.

What is the difference between a default constructor and a parameterised constructor?

Select the correct answer

1

A default constructor is provided by the base class while a parameterised one is written by the developer.

2

A default constructor cannot assign any fields while a parameterised one is implicitly declared as static.

3

A default constructor runs only once whereas a parameterised one executes on every method invocation.

4

A default constructor takes no arguments while a parameterised one accepts arguments to initialise state.

What is constructor overloading, and why would a class provide multiple constructors?

Select the correct answer

1

Redefining a parent class constructor inside a child class so the subclass can change its behaviour.

2

Providing a single constructor that accepts a variable number of arguments resolved later at runtime.

3

Declaring several constructors with different parameter lists so objects can be built in different ways.

4

Calling one constructor from another repeatedly to reuse initialisation logic across every subclass.

What is the purpose of a constructor, and can you explain constructor chaining and why it is used in inheritance hierarchies?

Select the correct answer

1

One constructor calls another to reuse setup and initialize the base class first.

2

One constructor overrides another so the most specific initializer always runs.

3

One constructor delays another until all subclass fields have been fully assigned.

4

One constructor copies another's fields to avoid duplicating initialization logic.

Under what circumstances would you define a constructor as private, and what does this achieve conceptually?

Select the correct answer

1

To block method calls, ensuring only internal code can invoke the object's behavior.

2

To block subclassing, ensuring the class stays final and cannot be extended later.

3

To block external instantiation, enabling singletons or factory-controlled creation.

4

To block field access, ensuring the object's state stays fully encapsulated always.

What is a copy constructor, and when would you use one instead of relying on default copying?

Select the correct answer

1

It merges two objects into one, combining their fields into a single new instance.

2

It resets an existing object's fields, reusing the instance instead of allocating one.

3

It builds a new object from an existing one, giving control over how copies form.

4

It duplicates a reference to an object, letting two variables share the same state.

What is the concept of a static factory method as a language feature, and how does it differ from using a constructor directly?

Select the correct answer

1

A static method that mutates shared global state each time it runs instead of returning a new object.

2

A method that overrides the default constructor to enforce singleton behaviour across the whole app.

3

A constructor variant that is marked static so it can be invoked without any instance of the class.

4

A static method returning an instance that, unlike a constructor, can be named and may reuse objects.

Explain the difference between 'Is-A' and 'Has-A' relationships.

Select the correct answer

1

Is-A models inheritance between types while Has-A models one object containing another object.

2

Is-A links two classes at runtime while Has-A links them only at compile time through imports.

3

Is-A describes interface implementation while Has-A describes overriding of inherited methods.

4

Is-A models object containment while Has-A models a subclass extending its parent class type.

Can you explain the different types of inheritance, single, multilevel, hierarchical, and hybrid?

Select the correct answer

1

Single shares one parent, multilevel combines types, hierarchical has one parent, hybrid forms a chain.

2

Single forms a chain, multilevel has one parent, hierarchical combines types, hybrid shares one parent.

3

Single has one parent, multilevel forms a chain, hierarchical shares one parent, hybrid combines types.

4

Single combines types, multilevel shares one parent, hierarchical forms a chain, hybrid has one parent.

Explain the difference between association, aggregation, and composition, and how does ownership and lifetime define a composition versus an aggregation?

Select the correct answer

1

In aggregation the part is owned and dies with the whole, while composition lets the part exist alone.

2

In association the part is owned and dies with the whole, while composition keeps the part independent.

3

In composition and aggregation alike the part always shares the exact lifetime of the whole object.

4

In composition the part is owned and dies with the whole, while aggregation lets the part outlive it.

Explain the is-a relationship, and what are the risks of creating an inheritance hierarchy that is too deep?

Select the correct answer

1

Is-a denotes composition; deep hierarchies improve reuse and always make the code easier to maintain later.

2

Is-a denotes inheritance; deep hierarchies raise coupling and fragility, making changes hard to reason about.

3

Is-a denotes delegation; deep hierarchies remove duplication and guarantee changes stay local to a class.

4

Is-a denotes aggregation; deep hierarchies reduce coupling but slow the running program down considerably.

What is the difference between Aggregation and Composition in terms of object lifetime?

Select the correct answer

1

In both composition and aggregation the contained object is destroyed together with its parent container.

2

In composition the contained object outlives its container, while in aggregation they share one lifetime.

3

In aggregation the contained object dies with its container, while in composition it exists on its own.

4

In composition the contained object dies with its container, while in aggregation it exists independently.

Why can a class implement multiple interfaces but not inherit from multiple classes in many languages?

Select the correct answer

1

Interfaces are resolved at runtime while classes resolve at compile time, avoiding clashes.

2

Classes are stored differently in memory, which physically prevents linking two parents.

3

Interfaces cannot contain any methods at all, so nothing they hold could ever conflict.

4

Interfaces declare behavior without shared state or implementation, so no ambiguity can arise.

What is a dependency relationship between classes, and how does it differ from an association?

Select the correct answer

1

A dependency is always bidirectional, while an association can only ever point one direction.

2

A dependency is a transient 'uses' link, while an association is a persistent structural relationship.

3

A dependency implies ownership of an object, while an association just means two classes coexist.

4

A dependency stores a reference as a field, while an association is only a temporary method call.

How do UML class diagrams represent relationships like inheritance, composition, and association, including multiplicity?

Select the correct answer

1

Inheritance uses a hollow diamond, aggregation a solid line, and multiplicity is never drawn on the ends.

2

Inheritance uses a hollow triangle, composition a filled diamond, and multiplicity numbers label the ends.

3

Inheritance uses a dashed arrow, association a filled diamond, and multiplicity appears inside each class box.

4

Inheritance uses a filled diamond, composition a hollow triangle, and multiplicity is shown by dashed lines.

What is the conceptual difference between class-based and prototype-based object orientation?

Select the correct answer

1

Class-based uses inheritance chains, while prototype-based forbids any reuse between objects.

2

Class-based supports encapsulation, while prototype-based cannot hide any internal data at all.

3

Class-based works only at runtime, while prototype-based fixes object structure at compile time.

4

Class-based creates objects from blueprints, while prototype-based clones and extends live objects.

What is the difference between Method Overloading and Method Overriding?

Select the correct answer

1

Overloading changes the return type only; overriding changes both the name and the parameter list entirely.

2

Overloading redefines an inherited method's body; overriding defines methods with differing parameter lists.

3

Overloading defines same-named methods with different signatures; overriding redefines an inherited method.

4

Overloading occurs only across classes; overriding occurs only within a single class's own method scope.

What is 'Method Overriding,' and what happens if a child class calls a method that exists in both the parent and the child?

Select the correct answer

1

Overriding merges both implementations; the parent's version runs first, then the child's version runs automatically.

2

Overriding replaces the parent's implementation; the child's version runs unless it explicitly calls super.

3

Overriding requires different signatures; the compiler picks whichever version best matches the arguments given.

4

Overriding hides the parent method; the parent's version runs unless the child casts itself upward first.

At a high level, what is polymorphism and why is it considered central to object-oriented design?

Select the correct answer

1

It enables methods to accept any number of arguments of arbitrary differing types.

2

It allows one class to inherit fields and methods from several parent classes at once.

3

It permits objects to change their class dynamically depending on the runtime context.

4

It lets a single interface represent many underlying types, enabling uniform treatment.

Explain the difference between compile-time (static) and runtime (dynamic) polymorphism with a conceptual example of each.

Select the correct answer

1

Static resolves calls at compile time via overloading; dynamic resolves at runtime via overriding.

2

Static resolves calls at runtime via overriding; dynamic resolves at compile time via overloading.

3

Static polymorphism applies to fields and data; dynamic applies to constructors and destructors.

4

Static polymorphism uses interfaces exclusively; dynamic uses only abstract base class methods.

What is method overriding, and how does it differ from method hiding or shadowing?

Select the correct answer

1

Overriding is resolved by the reference's declared type; hiding uses dynamic dispatch on the runtime type.

2

Overriding works only with static methods; hiding works only with instance methods marked as virtual.

3

Overriding uses dynamic dispatch on virtual methods; hiding is resolved statically by the reference's type.

4

Overriding requires identical signatures; hiding requires different signatures within the same hierarchy tree.

What is the difference between Upcasting and Downcasting, and what are the risks of the latter?

Select the correct answer

1

Upcasting converts a subtype to a supertype safely; downcasting reverses it and can fail at runtime.

2

Upcasting converts a supertype to a subtype and is always safe; downcasting reverses it and never fails.

3

Downcasting converts a subtype to a supertype safely; upcasting is risky and needs an explicit type check.

4

Upcasting and downcasting both change the object's actual type in memory, risking data loss on conversion.

What is a 'Virtual Method' conceptually, and how does 'Late Binding' work?

Select the correct answer

1

A virtual method can be overridden by subclasses, and late binding resolves the actual call at runtime.

2

A virtual method is abstract with no body, and late binding inlines the correct implementation during compilation.

3

A virtual method runs only on the base class, and late binding delays object creation until the call.

4

A virtual method cannot be overridden, and late binding chooses the method at compile time from the reference.

What are the rules for method overloading versus overriding, and can you overload a method by changing only the return type?

Select the correct answer

1

Overloading needs different parameter lists in a class; you cannot overload by only changing the return type.

2

Overloading needs the same parameters across classes; you can overload a method by only changing its return type.

3

Overriding needs different parameter lists; the return type alone is enough to distinguish two overloaded methods.

4

Overloading requires an inheritance relationship; changing only the return type creates a valid method overload.

Explain the concept of 'Subtype Polymorphism' without using code.

Select the correct answer

1

A single type is reused with different data structures, each supplying identical behavior for all callers.

2

A base type inherits behavior from its subtypes, letting callers reuse the most specialized version available.

3

One function name works on unrelated types by using type checks to select behavior at runtime.

4

Code written against a base type can operate on any subtype, each supplying its own behavior.

What is the difference between 'Early Binding' and 'Late Binding'?

Select the correct answer

1

Early binding resolves calls at compile time; late binding resolves them at runtime by actual object type.

2

Early binding links methods during object creation; late binding links them when the class is first loaded.

3

Early binding applies to static methods only; late binding applies to any method regardless of the object.

4

Early binding resolves calls at runtime; late binding resolves them at compile time using the reference type.

Explain the concept of 'Dynamic Dispatch' or 'Late Binding'.

Select the correct answer

1

The method implementation is fixed when the class loads, before any object is created.

2

The method implementation is chosen by the number of arguments passed at the call site.

3

The method implementation is selected at runtime based on the object's actual type.

4

The method implementation is selected at compile time from the reference's declared type.

Explain 'Covariance' and 'Contravariance' in the context of method overriding and return types.

Select the correct answer

1

Covariance and contravariance both require an override to keep identical parameter and return types every time.

2

Covariance allows an override to return a more derived type; contravariance allows accepting more general parameters.

3

Covariance allows an override to return a more general type; contravariance allows accepting more derived parameters.

4

Covariance lets an override accept more derived parameters; contravariance lets it return a more general result type.

What is the difference between subtype, parametric, and ad-hoc polymorphism?

Select the correct answer

1

Subtype, parametric, and ad-hoc all rely on runtime type checks to dispatch to the correct implementation.

2

Subtype works through generics, parametric through overloading, and ad-hoc through inheritance across broad type hierarchies.

3

Subtype works through overloading, parametric through inheritance, and ad-hoc through generic type parameters at runtime.

4

Subtype works through inheritance, parametric through generics over many types, ad-hoc through overloading for specific types.

How does Run-Time Type Information (RTTI) allow a program to determine an object's actual type at runtime?

Select the correct answer

1

The compiler resolves each object's exact type statically before the program executes.

2

Runtime metadata stored with each object identifies its actual class during execution.

3

The garbage collector scans references to infer each object's declared static type.

4

The linker assigns fixed type identifiers that cannot be inspected once loaded.

What is method resolution order as a concept, and why does it matter when a method exists at multiple levels of a hierarchy?

Select the correct answer

1

It defines the order base classes are searched to resolve a method appearing at multiple levels.

2

It defines the order constructors run so parent state is initialized before child state safely.

3

It defines the order methods compile so overloaded signatures bind to their correct parameters.

4

It defines the order fields are allocated so memory layout stays consistent across subclasses.

What is a pure virtual (abstract) method, and how does it force subclasses to provide behaviour?

Select the correct answer

1

A method declared without a body that subclasses must implement before they can be instantiated

2

A private method hidden from subclasses that supplies a fixed default behaviour for the class

3

A method with a body that subclasses may optionally override at runtime for polymorphism

4

A method resolved at compile time that cannot be overridden by any subclass at all

What is the difference between an Abstract Class and an Interface, and when would you choose one over the other?

Select the correct answer

1

Abstract classes hold state and partial implementation; interfaces declare behavior without state.

2

Abstract classes are resolved at runtime while interfaces are fully resolved during compilation.

3

Abstract classes cannot be extended further whereas interfaces can be freely implemented anywhere.

4

Abstract classes support multiple inheritance while interfaces are restricted to a single parent.

What is a 'Marker Interface,' and what is its purpose if it has no methods?

Select the correct answer

1

It marks a class as final so no subclass can override or extend its existing functionality.

2

It forces implementers to write empty method bodies purely to document future intended behavior.

3

It groups shared constants that many classes import, avoiding duplicate declarations elsewhere.

4

It tags a class with metadata so code can test type membership, despite having no methods.

What does it mean to say an interface is a contract, and how does this facilitate decoupled development between teams?

Select the correct answer

1

It enforces that both teams share the same class hierarchy before any development work can begin.

2

It guarantees runtime behavior is identical across every class that chooses to implement the type.

3

It records concrete implementation details so consumers know exactly how each operation is performed.

4

It specifies what operations exist without implementation, letting teams build against it independently.

Can an Interface have a constructor? Why or why not?

Select the correct answer

1

No, because constructors are inherited from the first concrete class that implements it later.

2

No, because an interface cannot be instantiated and holds no instance state to initialize.

3

Yes, but only a private constructor used internally to set up its default constant values.

4

Yes, provided the constructor takes no arguments and simply returns the interface instance.

How do 'Default Methods' in interfaces change the traditional definition of an interface?

Select the correct answer

1

They let interfaces be instantiated directly, so simple types no longer need an implementing class.

2

They let interfaces declare private fields, so implementing classes can share mutable state safely.

3

They let interfaces run before construction, so setup logic executes ahead of any concrete class.

4

They let interfaces provide method implementations, so interfaces are no longer purely abstract.

What is the difference between a default (interface) method and a regular abstract method, and how do default methods affect interface evolution?

Select the correct answer

1

A default method can only be called statically and cannot be overridden by any implementing class

2

A default method has no body and must be implemented, while abstract methods carry a fallback body

3

A default method forces every existing implementer to recompile and supply its own new behaviour

4

A default method provides a body so implementers need not override it, easing interface evolution

Why is it often said that you should favour composition over inheritance, and what are the specific trade-offs in flexibility?

Select the correct answer

1

Composition assembles behaviour from objects at runtime, giving more flexibility than rigid inheritance

2

Composition always runs faster than inheritance because no virtual dispatch is ever needed

3

Composition removes all coupling entirely, so classes never depend on one another anymore

4

Inheritance is preferred because composition breaks encapsulation and exposes internal object state

Explain the concept of substitutability: why should a derived class be able to stand in for its base class without breaking the program?

Select the correct answer

1

A subclass must honour the base class contract so client code works unchanged with either

2

A subclass must add new methods so it can fully replace the base class in all cases

3

A subclass must be smaller than its base class to safely stand in wherever it is used

4

A base class must expose all its fields publicly so subclasses can override behaviour freely

What does it mean for two objects to be 'Tightly Coupled,' and how does OOP help achieve 'Loose Coupling'?

Select the correct answer

1

Tightly coupled objects share a common base class; polymorphism removes the shared inheritance need

2

Tightly coupled objects depend on each other's details; interfaces and abstraction reduce that dependency

3

Tightly coupled objects run in the same thread; message passing separates them into different threads

4

Tightly coupled objects have identical methods; encapsulation hides those methods to loosen the link

How do you identify potential classes and responsibilities from a set of requirements?

Select the correct answer

1

Verbs in the requirements suggest candidate classes and nouns suggest their responsibilities

2

Classes are derived only from the database schema, not from the written requirements text

3

Each requirement sentence becomes exactly one class with one responsibility by definition

4

Nouns in the requirements suggest candidate classes and verbs suggest their responsibilities

What does 'High Cohesion' mean for a class, and why is it desirable?

Select the correct answer

1

A class exposes all its fields directly so related objects can share state more efficiently

2

A class holds as many methods as possible so callers rarely need other classes around

3

A class depends heavily on other classes so its behaviour stays consistent across the system

4

A class's members focus on a single, well-defined responsibility, making it easier to maintain

In the context of object design, what does it mean to have high cohesion and low coupling, and why is this the gold standard?

Select the correct answer

1

A class handles one focused responsibility with minimal dependencies on other classes.

2

A class depends heavily on others while keeping its internal methods loosely related.

3

A class handles many responsibilities but shares no data with other classes at all.

4

A class exposes all of its fields publicly so other classes can freely reuse them.

How do you decide what should be a class versus what should be an attribute when modeling a real-world system?

Select the correct answer

1

Make it a class if it stores a single value, else always model it as an attribute.

2

Make it a class only when it holds numbers, and an attribute when it holds text.

3

Make it a class if it appears once, else an attribute when it repeats many times.

4

Make it a class if it has its own behavior and identity, else an attribute.

What is the fragile base class problem, and how does it affect the long-term maintenance of a system?

Select the correct answer

1

Subclasses fail to compile whenever the base class exposes any protected or private fields

2

Adding a new subclass forces the base class to be rewritten to support that subclass

3

A base class becomes unusable once too many subclasses inherit from it at the same time

4

Changes to a base class can silently break subclasses that depend on its internal behaviour

What are the tradeoffs of using deep Inheritance hierarchies?

Select the correct answer

1

It improves runtime speed but forces every subclass to override all parent methods.

2

It simplifies testing but makes the base class impossible to instantiate on its own.

3

It reduces memory usage but stops subclasses from adding any new behavior later on.

4

It maximizes code reuse but makes subclasses fragile and tightly coupled to parents.

Explain the gorilla-banana problem in inheritance.

Select the correct answer

1

Inheriting deeply makes the compiler load classes slowly due to long parent chains.

2

Inheriting one feature drags in all the parent's unwanted state and behavior too.

3

Inheriting an interface forces you to implement methods you will never actually call.

4

Inheriting from two parents causes conflicting method names that cannot be resolved.

What is the purpose of an object's string representation (toString), and why is overriding it useful?

Select the correct answer

1

It produces a human-readable textual form of an object, and overriding it yields meaningful output for logging and debugging

2

It compares two objects for equality, and overriding it lets collections locate and deduplicate stored items correctly

3

It serializes an object into a binary format, and overriding it ensures the stored bytes remain portable across systems

4

It generates a unique hash for an object, and overriding it keeps hash-based containers balanced and performant

What is the difference between a Shallow Copy and a Deep Copy when cloning an object?

Select the correct answer

1

A shallow copy duplicates all nested objects; a deep copy only copies the top level.

2

A shallow copy shares nested objects by reference; a deep copy duplicates them fully.

3

A shallow copy is always faster while a deep copy always fails on immutable fields.

4

A shallow copy clones primitives only while a deep copy clones nothing but pointers.

Explain the concept of 'Object Equality' versus 'Object Identity.' How do they differ?

Select the correct answer

1

Equality checks the memory address; identity compares the contents of two objects.

2

Equality applies only to primitives; identity applies only to reference-type objects.

3

Equality compares values or state; identity checks if it's the very same instance.

4

Equality is always reflexive but identity can change whenever an object is mutated.

What is an immutable object, and what are the benefits of designing classes to be immutable by default?

Select the correct answer

1

Its methods are all static, so instances never need to be created or destroyed later.

2

Its state cannot change after creation, making it thread-safe and easy to share.

3

Its fields are all public constants, letting other objects modify them without copying.

4

Its state can change only once after creation, which prevents accidental data races.

What is the contract between equals and hashCode, and why must two 'equal' objects produce the same hash code?

Select the correct answer

1

Unequal objects must always share a hash code to avoid collisions inside the map.

2

Equal objects must share a hash code so hash-based collections can find them.

3

Equal objects must have different hash codes so they occupy separate hash buckets.

4

Hash codes must equal the object's identity so equals can reuse the same address.

What is the purpose of generics in OOP, and how do they improve type safety without sacrificing reusability?

Select the correct answer

1

They cast objects dynamically at runtime, giving flexible storage while a single container tolerates any inserted concrete type

2

They parameterize code over types, giving compile-time checking while a single implementation works for many concrete types

3

They overload methods per type signature, giving distinct behavior while one class name covers many parameter combinations

4

They defer type resolution to reflection, giving late binding while a single interface adapts to unknown concrete types

What is operator overloading conceptually, and what are the risks of abusing it?

Select the correct answer

1

Defining multiple methods with one operator name; abuse yields ambiguous resolution that forces explicit casting everywhere

2

Giving operators custom meaning for user types; abuse yields surprising, unintuitive semantics that reduce code readability

3

Redefining built-in operators globally for all types; abuse yields runtime conflicts that break unrelated library code silently

4

Mapping operators to virtual dispatch at runtime; abuse yields slower arithmetic that degrades performance in tight loops

What is a finalizer or destructor conceptually, and why are finalizers considered unreliable for resource cleanup?

Select the correct answer

1

A method invoked explicitly by the programmer at end of use; unreliable because forgetting to call it leaves resources permanently leaked

2

A method that frees memory as soon as an object is created; unreliable because it blocks other threads during allocation cycles

3

A method run by the garbage collector before reclaiming an object; unreliable because its timing is nondeterministic and it may never run

4

A method run automatically when an object leaves scope; unreliable because it cannot safely access any of the object's instance fields

What is 'Reflection' (or Introspection) in OOP, and what are its use cases and risks?

Select the correct answer

1

Resolving method calls through the vtable at runtime; useful for polymorphism but risks slower dispatch and tight coupling

2

Inspecting and modifying types and members at runtime; useful for frameworks but risks poor performance and broken encapsulation

3

Rewriting compiled bytecode ahead of time; useful for optimization but risks portability loss and difficult debugging sessions

4

Copying an object graph deeply at runtime; useful for caching but risks stale references and heavy memory consumption

What is the 'Diamond Problem' in multiple inheritance, and how do different languages conceptually resolve it?

Select the correct answer

1

Deadlock when two classes reference each other cyclically; resolved by lazy loading, forward declarations, or weak reference pointers

2

Leakage when a base class exposes private state; resolved by sealing classes, hiding fields, or enforcing strict accessor rules

3

Slowdown when a deep hierarchy resolves virtual calls; resolved by caching dispatch, inlining methods, or flattening the class tree

4

Ambiguity when a class inherits one member via two paths; resolved by linearization, virtual bases, or banning multiple inheritance

What are mixins or traits conceptually, and how do they provide a middle ground for languages that don't support multiple inheritance?

Select the correct answer

1

Reusable bundles of behavior composed into a class, sharing methods across types without full multiple inheritance

2

Abstract contracts declaring only signatures, forcing each class to supply its own concrete implementation of behavior

3

Parameterized templates generating specialized classes, letting types share code while remaining strongly typed at compile time

4

Runtime wrappers that intercept method calls, injecting shared logic around existing behavior without altering the class

What is the purpose of a Virtual Destructor?

Select the correct answer

1

It guarantees a destructor is invoked exactly once even when multiple threads share the same object pointer, preventing races

2

It forces derived classes to declare their own destructor so cleanup logic is never accidentally inherited from a base

3

It ensures the correct derived destructor runs when an object is deleted through a base-class pointer, preventing leaks

4

It defers destruction until every reference is gone by reference counting, so the object is freed once safely at the end

What is virtual inheritance conceptually, and what problem in inheritance hierarchies is it meant to address?

Select the correct answer

1

It ensures constructors run in a deterministic order, addressing uninitialized members across a deep inheritance chain

2

It ensures a base class cannot be instantiated directly, addressing accidental creation of incomplete abstract object types

3

It ensures a shared base class is inherited only once, addressing duplicated base subobjects in diamond hierarchies

4

It ensures derived methods override base ones dynamically, addressing incorrect static binding when calling through pointers