Class and Object Basics
Encapsulation
Inheritance
Polymorphism
Advanced OOP Concepts
100

What is a class?

A blueprint for creating objects; it defines attributes and behaviors.

100

What does encapsulation mean in OOP?

Encapsulation is the concept of bundling data and methods together and restricting direct access to some of an object’s components.

100

What is inheritance in object-oriented programming?

Inheritance is the mechanism by which one class (child/subclass) can acquire properties and methods from another class (parent/superclass).

100

What is polymorphism?

Polymorphism allows methods or objects to take on multiple forms, typically through method overloading or overriding.

100

What is an abstract class?

A class that cannot be instantiated and may include abstract methods that must be implemented by subclasses.


200

What keyword is typically used to create a new object in many languages like C++ or Python?

new in C++ or directly calling the class name in Python.

200

How do you make a variable private in most OOP languages?

By declaring it with the private keyword.

200

What keyword is used to inherit a class?
 

In C++, the keyword used to inherit a class is the colon (:) followed by an access specifier and the name of the base class.

200

What’s the difference between method overloading and method overriding?

Overloading is having multiple methods with the same name but different parameters; overriding is redefining a superclass method in a subclass.

200

What is an interface?

An interface defines a contract of methods that implementing classes must fulfill, but contains no implementation itself.

300

What is the purpose of a constructor in a class?

To initialize objects when they are created, often setting default values for attributes.

300

Why do we use getter and setter methods in OOP?

To control access to private variables and maintain encapsulation.


300

What are a superclass and a subclass?

A superclass is the parent class being inherited from; a subclass is the child class that inherits from it.

300

What is dynamic dispatch in OOP?

It’s the process by which a call to an overridden method is resolved at runtime based on the actual object.

300

What’s the difference between an abstract class and an interface?

Abstract classes can have both defined and abstract methods, while interfaces only define method signatures (in most languages).

400

To initialize objects when they are created, often setting default values for attributes.

A class is a blueprint; an object is an instance of that class.

400

What happens if you try to access a private variable directly from outside its class?

It will result in a compilation or runtime error depending on the language.

400

Can a subclass override a method from its superclass?

Yes, a subclass can provide its own implementation of a method defined in the superclass.

400

How does C++ determine which method to execute when polymorphism is used?


C++ uses dynamic dispatch via virtual functions to determine at runtime which method to execute. If a method is declared with the virtual keyword in the base class and is overridden in a derived class, the actual type of the object (not the pointer or reference type) determines which method gets called.

400

What is the SOLID principle in OOP?

A set of five design principles (Single responsibility, Open/closed, Liskov substitution, Interface segregation, Dependency inversion) to create maintainable and scalable software.

500

What is an instance variable and how is it accessed?

An instance variable is unique to each object; it is accessed using objectName.variableName.

500

How does encapsulation improve modularity and security?

It hides implementation details and protects data integrity by exposing only necessary parts of the code.

500

How do constructors behave when using inheritance?

The constructor of the parent class is called first, either automatically or explicitly via super()

500

How does an object-oriented language decide which overridden method to call?

At runtime, based on the actual type of the object, not the reference type.

500

What is dependency injection and why is it used?

It's a design pattern where objects are passed their dependencies; it improves testability and modularity.