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?
Alice \n 20 \n S12345
S12345 \n Alice \n 20
Alice \n S12345 \n 20
20 \n Alice \n S12345
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:

Your comments will be displayed after verification.