Python Programming - Objects - Discussion
Discussion Forum : Objects - General Questions (Q.No. 10)
10.
Consider the following Python code:
class Student:
def __init__(self, name, age):
self.name = name
self.age = age
def birthday(self):
self.age += 1
If you create an instance of the Student class called john
with age 20 and then call john.birthday()
, what will be the updated age?
Answer: Option
Explanation:
The
birthday
method increments the age attribute by 1, so after calling john.birthday()
, the updated age will be 21.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers