What is a class?
A blueprint for creating objects; it defines attributes and behaviors.
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.
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).
What is polymorphism?
Polymorphism allows methods or objects to take on multiple forms, typically through method overloading or overriding.
What is an abstract class?
A class that cannot be instantiated and may include abstract methods that must be implemented by subclasses.
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.
How do you make a variable private in most OOP languages?
By declaring it with the private keyword.
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.
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.
What is an interface?
An interface defines a contract of methods that implementing classes must fulfill, but contains no implementation itself.
What is the purpose of a constructor in a class?
To initialize objects when they are created, often setting default values for attributes.
Why do we use getter and setter methods in OOP?
To control access to private variables and maintain encapsulation.
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.
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.
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).
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.
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.
Can a subclass override a method from its superclass?
Yes, a subclass can provide its own implementation of a method defined in the superclass.
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.
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.
What is an instance variable and how is it accessed?
An instance variable is unique to each object; it is accessed using objectName.variableName.
How does encapsulation improve modularity and security?
It hides implementation details and protects data integrity by exposing only necessary parts of the code.
How do constructors behave when using inheritance?
The constructor of the parent class is called first, either automatically or explicitly via super()
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.
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.