Classes and OOP Flashcards

1
Q

What is a class?

A

A class is a blueprint for an object in python, containing all properties, attributes, methods etc.

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

Do classes create their own scope?

A

No, one must be very explicit when referring to things inside the class.

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

What are the three main ideas of OOP?

A
Inheritance: the ability for a new class to specialise/modify the behaviour of existing classes.
Polymorphism, dynamic binding and duck typing: The ability to use an instance without regard for its type
Data encapsulation and private attributes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do you call a class that you inherit from?

A

parent/super class

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

What is a static method?

A

A function defined inside a class, does not operate on the instance.

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

What is a Class method?

A

A method operating on the class itself as opposed to an instance.

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

How would you make a class attribute private?

A

self.__ = …

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

Can private attributes be accessed outside the class?

A

Not directly, but they are not truly private.

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

What are getters and setters?

A

Allow for updated interdependent attributes

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

Explain the @property decorator (implement it in code)

A

Properties are calculated when accessed, meaning you can update dependent attributes.

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