Python Programming - Classes - Discussion
Discussion Forum : Classes - General Questions (Q.No. 38)
38.
Consider the following Python code:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
class Student(Person):
def __init__(self, name, age, student_id):
super().__init__(name, age)
self.student_id = student_id
# Create an instance of the Student class
my_student = Student("Alice", 20, "S12345")
# Access and print attributes
print(my_student.name)
print(my_student.age)
print(my_student.student_id)
What will be the output of the code?
Answer: Option
Explanation:
The code creates an instance of the `Student` class and prints the values of its attributes (`name`, `age`, `student_id`).
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