Knowee
Questions
Features
Study Tools

What will be the output of the following Python code?class program:  def __init__(self, param):    self.o1 = param class code(program):  def __init__(self, param):    self.o2 = param ct = code(22)print ("%d %d" % (ct.o1, ct.o2))OptionsNone NoneNone 2222 NoneError is generated

Question

What will be the output of the following Python code?class program:  def init(self, param):    self.o1 = param class code(program):  def init(self, param):    self.o2 = param ct = code(22)print ("%d %d" % (ct.o1, ct.o2))OptionsNone NoneNone 2222 NoneError is generated

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the given Python code will be an error. This is because when you create an object of the subclass 'code', it does not automatically call the constructor of the superclass 'program'. Therefore, 'o1' is not an attribute of the 'ct' object and trying to access 'ct.o1' will result in an AttributeError.

Similar Questions

what is the output of following python code? class myclass:    def __init__(self,a):        self.a = a        print(self.a)o=myclass()

What will be the output of the following code?class MyClass:    def __init__(self, value=5):        self.value = valueobj1 = MyClass()obj2 = MyClass(10)print(obj1.value, obj2.value)5 1010 50 10None None

Choose the Correct Answer(s)What is the output of the following code?class test: def __init__(self): print ("Hello World") def __init__(self): print ("Happy Coding")obj = test()OptionsHappy CodingHappy WorldHello WorldNone of the above

What will be the output of the following Python code?class Demo: def __init__(self): self.a = 1 self.__b = 1 def get(self): return self.__bobj = Demo()obj.a=45print(obj.a)

What will be the output of the following Python code?class Demo: def __new__(self): self.__init__(self) print("Demo's __new__() invoked") def __init__(self): print("Demo's __init__() invoked")class Derived_Demo(Demo): def __new__(self): print("Derived_Demo's __new__() invoked") def __init__(self): print("Derived_Demo's __init__() invoked")def main(): obj1 = Derived_Demo() obj2 = Demo()main()Derived_Demo’s __init__() invokedDerived_Demo's __new__() invokedDemo's __init__() invokedDemo's __new__() invokedDerived_Demo's __new__() invokedDemo's __init__() invokedDemo's __new__() invokedDerived_Demo's __new__() invokedDemo's __new__() invokedDerived_Demo’s __init__() invokedDemo's __init__() invoked

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.