OOP Junior

1 / 20

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

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

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.

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.

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.

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