Questions: Introduction to Classes

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A programmer defines a class Dog with an attribute `name`. She then creates two instances: dog1 = Dog('Rex') and dog2 = Dog('Luna'). She later runs dog1.name = 'Max'. What happens to dog2.name?

Adog2.name also changes to 'Max' because both objects share the same class
Bdog2.name remains 'Luna' because each instance has its own independent state
Cdog2.name becomes None because the class definition was modified
DAn error is raised because you cannot modify one instance without modifying all
Question 2 Multiple Choice

What does `self` refer to inside a class method, and why is it necessary?

AIt refers to the class itself, allowing methods to access the class definition
BIt is a keyword that marks the method as belonging to the class rather than being a standalone function
CIt refers to the specific instance the method was called on, connecting the method to that object's data
DIt refers to the parent class, enabling inheritance from built-in types
Question 3 True / False

Defining a class in Python immediately creates an object in memory that you can use.

TTrue
FFalse
Question 4 True / False

Two different instances created from the same class can have different values for their attributes.

TTrue
FFalse
Question 5 Short Answer

Why does every instance method in Python require `self` as its first parameter? What would break if `self` were omitted?

Think about your answer, then reveal below.