Classes & Objects questions and answers

Attributes, inheritance, super(), dunder methods and properties. Practise classes & objects questions from the python section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.

Sample classes & objects questions with worked answers

Question 1

Inside a method defined in a class, what does the first parameter, conventionally named self, refer to?

  1. The particular object on which the method was called
  2. The class in which the method is defined
  3. The parent class of the current class
  4. The module that contains the class

Answer: A. The particular object on which the method was called

Explanation: When you write obj.method(), Python passes obj itself as the first argument. That is how the method reaches the attributes of that specific object.

Question 2

What is the key difference between a method marked @classmethod and one marked @staticmethod?

  1. A static method can be called only on an object, never on the class
  2. A class method cannot be inherited by child classes, but a static method can
  3. A static method automatically receives the object as its first argument; a class method receives nothing
  4. A class method automatically receives the class as its first argument; a static method receives no automatic argument

Answer: D. A class method automatically receives the class as its first argument; a static method receives no automatic argument

Explanation: @classmethod passes the class (usually named cls) as the first argument, so it can read or change class-level data. @staticmethod is a plain function kept inside the class and gets neither self nor cls.

Question 3

D inherits from both B and C, and B and C both inherit from A. Which who() runs, and what is D's method resolution order?

class A:
    def who(self): return "A"
class B(A):
    def who(self): return "B"
class C(A):
    def who(self): return "C"
class D(B, C):
    pass

print(D().who(), [k.__name__ for k in D.__mro__])
  1. B ['D', 'B', 'A', 'C', 'object']
  2. C ['D', 'C', 'B', 'A', 'object']
  3. B ['D', 'B', 'C', 'A', 'object']
  4. A ['D', 'A', 'B', 'C', 'object']

Answer: C. B ['D', 'B', 'C', 'A', 'object']

Explanation: Python searches D first, then the parents in the order they are listed, B then C, and only after both does it go to their shared parent A. B is found first, so who() returns B.

All 20 classes & objects questions with answers

Classes & Objects: common questions

What are classes & objects questions?

Attributes, inheritance, super(), dunder methods and properties. They appear in the python section of many placement tests.

Where can I practise classes & objects questions with answers for free?

Right here on LogicWiz Exams. Every classes & objects question has a worked explanation after you answer. Practice is free and needs no sign-up.

How should I practise classes & objects?

Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.

Start practising

On this page you can start a fresh set of classes & objects questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: Python practice.

More python topics

Other subjects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep