Examveda

What will be the output of the following Python code?
class test:
     def __init__(self,a="Hello World"):
         self.a=a
 
     def display(self):
         print(self.a)
obj=test()
obj.display()

A. The program has an error because constructor can't have default arguments

B. Nothing is displayed

C. "Hello World" is displayed

D. The program has an error display function doesn't have parameters

Answer: Option C


This Question Belongs to Python Program >> Classes And Objects In Python

Join The Discussion

Related Questions on Classes and Objects in Python