Classes & Objects · Question 8 · Medium
wheels is a class attribute of Car, and it is then assigned through one object. What do the three lookups print?
class Car:
wheels = 4
a = Car()
b = Car()
a.wheels = 3
print(a.wheels, b.wheels, Car.wheels)
- 3 3 3
- 3 4 3
- 4 4 4
- 3 4 4
Answer and explanation
Answer: D. 3 4 4
Explanation: Assigning a.wheels = 3 creates an instance attribute on a only; it does not touch the class attribute. b has no attribute of its own, so it still reads 4 from the class.
Previous: The method on() in the Lamp class is written without a self parameter. What… · Next: The child class Student defines its own __init__ and does not call the…
Practise classes & objects
Try a fresh set of classes & objects questions with an explanation after every answer, free and without signing up: Classes & Objects practice. Or sit a full placement mock test.
More classes & objects questions
- Manager inherits from Employee and defines nothing of its own. What does…
- Square overrides the area method of its parent Shape. What is printed for a…
- The method on() in the Lamp class is written without a self parameter. What…
- The child class Student defines its own __init__ and does not call the…
- Three classes in a chain each extend fee() using super(). What does the last…
- The Point class defines __eq__. What do == and is give for two separately…
- A class method reads a counter that __init__ increases on the class. What is…
- fahrenheit is declared with @property and is accessed without brackets. What…
- What is the key difference between a method marked @classmethod and one marked…
- B is a child of A. What do isinstance, a direct type comparison and issubclass…
More python practice
Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge