Object Oriented Programming Flashcards

(34 cards)

1
Q

Define object-oriented programming.

A

A programming paradigm based on the concept of objects, which can contain data and code.

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

What is an object in OOP?

A

An instance of a class that contains attributes and methods.

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

True or false: Encapsulation hides the internal state of an object.

A

TRUE

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

Fill in the blank: Inheritance allows a class to _______ properties of another class.

A

inherit

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

What is a class in OOP?

A

A blueprint for creating objects, defining attributes and methods.

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

Define polymorphism.

A

The ability to present the same interface for different data types.

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

What does the self keyword represent in Python?

A

It refers to the instance of the class in method definitions.

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

True or false: A class can have multiple constructors in Python.

A

FALSE

Python does not support method overloading, including constructors.

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

What is the purpose of the __init__ method?

A

To initialize an object’s attributes when it is created.

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

Fill in the blank: A method is a function defined within a _______.

A

class

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

What is abstraction in OOP?

A

The concept of hiding complex implementation details and showing only essential features.

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

Define class variable.

A

A variable that is shared among all instances of a class.

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

What is a module in Python?

A

A file containing Python code that can define functions, classes, and variables.

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

True or false: Composition is a way to achieve code reuse by including objects in other objects.

A

TRUE

Composition allows building complex types by combining simpler ones.

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

What does super() do in Python?

A

It allows access to methods from a parent class.

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

Fill in the blank: A getter method retrieves the value of a _______.

17
Q

What is the purpose of a setter method?

A

To set or update the value of a property in a class.

18
Q

Define abstract class.

A

A class that cannot be instantiated and is meant to be subclassed.

19
Q

What is method overriding?

A

When a subclass provides a specific implementation of a method already defined in its superclass.

20
Q

True or false: An interface defines methods without implementing them.

A

TRUE

Interfaces are used to enforce certain functionalities in classes.

21
Q

What is a constructor?

A

A special method that is called when an object is instantiated.

22
Q

Fill in the blank: Duck typing in Python means that the type of an object is determined by its _______.

23
Q

What is the significance of __str__ method?

A

It defines a string representation of an object for printing.

24
Q

Define instance variable.

A

A variable that is unique to each instance of a class.

25
What does **isinstance()** function do?
Checks if an object is an instance of a specified class or a subclass.
26
True or false: **Static methods** can access class and instance variables.
FALSE ## Footnote Static methods do not have access to the instance or class variables.
27
What is the purpose of **__repr__** method?
To provide an unambiguous string representation of an object for debugging.
28
Fill in the blank: **Multiple inheritance** allows a class to inherit from _______ classes.
multiple
29
What is a **property** in Python?
A special kind of attribute that allows for getter and setter methods.
30
Define **mixins**.
Classes that provide methods to other classes through inheritance, but are not meant to stand alone.
31
What does **__del__** method do?
It defines behavior for when an object is about to be destroyed.
32
True or false: **Encapsulation** promotes loose coupling in OOP.
TRUE ## Footnote Loose coupling allows for easier maintenance and flexibility.
33
What is **dynamic typing** in Python?
The type of a variable is determined at runtime, not in advance.
34
Fill in the blank: **Delegation** is when an object relies on another object to _______ a task.
perform