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)
  1. 3 3 3
  2. 3 4 3
  3. 4 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

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