Object Oriented Programming Flashcards
What is an object in OOP?
an entity or thing in your program
how do you create objects in Python?
Using classes. Classes define a type (not default types like str, int). Process of creating an object from that class is called instantiation.
True or False - Objects of the same class are independent of each other.
True. The class just tells python how to create the objects.
Write a class named Dog that has no input parameters and all it does is pass.
class Dog: pass
What are instance attributes?
Attributes that are independent to each object
What value do you pass in for ‘self’ when creating an object?
Nothing. Self is used to refer to the current object being created during instantiation.
What does self mean?
Take the value we are passing in and assign it to the attribute for the new instance.
What are class attributes?
Attributes that are the same for each instance of the class.
What is an instance method?
An instance method is a function that belongs to a class. Just like functions, these methods can accept parameters, and they can access the attributes of the object they belong to.
What is inheritance?
Inheritance is the OOP concept that allows one class to subclass another.
What is overwriting in Python when referring to class attributes?
Overwriting can allow for a class which inherits attributes from a parent, to overwrite one of the attributes.
Can you overwrite / add methods to children classes?
Yes.