Classes & Objects · Question 3 · Easy

The deposit method of an Account object is called twice. What does the second call return?

class Account:
    def __init__(self):
        self.balance = 0
    def deposit(self, amount):
        self.balance += amount
        return self.balance

a = Account()
a.deposit(500)
print(a.deposit(250))
  1. 250
  2. 500
  3. 750
  4. None
Answer and explanation

Answer: C. 750

Explanation: balance belongs to the object and is kept between calls. After the first deposit it is 500, and the second adds 250 to give 750.

Previous: Inside a method defined in a class, what does the first parameter… · Next: Which special method does Python call automatically, right after an object is…

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