OOP Senior

1 / 21

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.

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.

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.

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.

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

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 '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