Find the output of the given code in python

Question

a= A(7)
del a.x
print (a.x)" AttributeError
"What is the output of the following code?
Class A:
@classmethod
def getC(self):
print ('In Class A, method getC.')
class B(A):
pass
b= B()
B.getC()
b.grtC()" " In Class A, method getC.
In class A, method getC

 

Summary

In the above question, we have to find the output of the given code in python language. Code has a different function. The output of this program will be In Class A, method getC.
In Class A, method getC.

Explanation

We have a program code in python in which Class A and Class B are two different classes defined here. Both the classes have their own functions. Class A has a print statement and in that print statement, there is an output statement that is printed on the screen.
Class B has a parameter of name Class A. So the statement in class A will also get printed in class B. That’s why we can see the two output statements in the output screen. Also, there is two functions calling with the b variable.

Code

class A:
    @classmethod
    def getC(self):
        print("In Class A, method getC.")

class B(A):
    pass 

b=B() 
B.getC()
b.getC()

Output

code in python

 

Also read, Consider the class diagram below figure which illustrates the data model for the supervision of student projects

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *