OOP Flashcards

1
Q

What is Object-Oriented Programming?

A

A programming paradigm based on the concept of “objects” which can contain data (attributes) and code (methods), and which interact through defined interfaces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the four main principles of OOP?

A

Encapsulation

Abstraction

Inheritance

Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is encapsulation in OOP?

A

The bundling of data with the methods that operate on that data, and restricting direct access to some of an object’s components.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How is encapsulation typically implemented?

A

Through access modifiers (private, protected, public) and getter/setter methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is inheritance in OOP?

A

A mechanism where a new class (child) is derived from an existing class (parent), inheriting its attributes and methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the benefits of inheritance?

A

Code reusability

Method overriding (polymorphism)

Creating hierarchical classifications

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is polymorphism in OOP?

A

The ability of objects to take on many forms, typically through method overriding (runtime polymorphism) or method overloading (compile-time polymorphism).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What’s the difference between method overloading and overriding?

A

Overloading: Same method name, different parameters (compile-time)

Overriding: Same method signature in child class (runtime)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is abstraction in OOP?

A

Hiding complex implementation details and showing only essential features of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is abstraction implemented?

A

Through abstract classes and interfaces that define what an object does without specifying how it does it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a class in OOP?

A

A blueprint or template for creating objects, defining their properties and behaviors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an object in OOP?

A

An instance of a class that contains data (attributes) and behavior (methods).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an interface?

A

A completely abstract class that defines a contract (methods) that implementing classes must follow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an abstract class?

A

A class that cannot be instantiated and may contain both abstract and concrete methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is composition in OOP?

A

A design principle where a class contains objects of other classes (has-a relationship) rather than inheriting from them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the difference between “is-a” and “has-a” relationships?

A

“Is-a” = inheritance (a Car is a Vehicle)

“Has-a” = composition (a Car has an Engine)

17
Q

What is the SOLID principle in OOP?

A

Five design principles:

Single Responsibility

Open/Closed

Liskov Substitution

Interface Segregation

Dependency Inversion

18
Q

What is the Single Responsibility Principle?

A

A class should have only one reason to change, meaning it should have only one responsibility or job.

Example:

❌ Bad: A User class that handles user data and saves to a database.

✅ Good: Separate User (data) and UserRepository (database operations).

19
Q

What does the Open/Closed Principle state?

A

Software entities (classes, modules, functions) should be open for extension but closed for modification.

Example:

❌ Bad: Modifying an existing PaymentProcessor class to add new payment methods.

✅ Good: Using interfaces (CreditCardPayment, PayPalPayment) to extend functionality without changing existing code.

20
Q

What does the Liskov Substitution Principle state?

A

Subtypes must be substitutable for their base types without altering the correctness of the program.

Example:

❌ Bad: A Square class inheriting from Rectangle but changing setWidth() behavior, breaking expectations.

✅ Good: Ensuring derived classes do not violate base class behavior.

21
Q

What does the Interface Segregation Principle state?

A

Clients should not be forced to depend on interfaces they do not use. Split large interfaces into smaller, specific ones.

Example:

❌ Bad: A single Worker interface with work(), eat(), and sleep().

✅ Good: Separate Workable, Eatable, and Sleepable interfaces.

22
Q

What does the Dependency Inversion Principle state?

A

High-level modules should not depend on low-level modules. Both should depend on abstractions.

Abstractions should not depend on details. Details should depend on abstractions.

Example:

❌ Bad: A ReportGenerator class directly depending on MySQLDatabase.

✅ Good: ReportGenerator depending on a Database interface, allowing any database implementation.