Object Oriented Programming Flashcards

1
Q

An object

A

An instance of a class

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

How do you create a class

A

Class (Name):

(Here you would add attributes/characteristics e.g)

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

Features of a class

A

Methods, attributes,constructor

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

A constructor

A

A method that constructs objects (e.g the init method)

__init__(self):

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

Def __init__(self)

A

Constructor

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

What arguments need to be passed into the init method

A

The attributes you want to give an object

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

What do I have to put before each variable/attribute with the init method

A

Self.

(This is because they are the attributes relating to “self” the object)

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

If I wanted an attribute for my object such as hair how would it look in my constructor

A

Def __init__(self,hair):
Self.hair = hair

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

Instance variables

A

A variable which depends on the specific object (can be unique to particular object)

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

Class variables

A

A variable that is true to all objects of a class unless changed by calling the variable of an object or of the entire class

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

How does method chaining work?

A

Method chaining works by having multiple methods come after one another in a single line

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

Write a method chain for the object dog

With the first method being run and the next being bark

A

dog = Dog()
dog.run().bark()

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

What must be returned when method chaining?

A

Self

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

Super() or super function

A

Function used to give access to methods of a parent class. Returns a temporary object of a parent class when used.

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

How do you pass an object as an argument?

A

You put the object into the functions brackets 🤠

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

What is duck typing?

A

A concept where the class of an object is less important than the methods/attributes that the class might have, class type is not checked or minimum methods/ attributes are present.

17
Q

What is the phrase for duck typing?

A

“If it walks like a duck, and it quacks like a duck, then it must be a duck.”