Q:

What will be the output of the following Python code?

0

What will be the output of the following Python code?

class A: 
def __init__(self): self.__x = 1 
class B(A): 
def display(self): 
print(self.__x) 
def main(): 
obj = B() 
obj.display() 
main()

Private class members in the superclass can’t be accessed in the subclass.


  1. Error, invalid syntax for object declaration
  2. Error, private class member can’t be accessed in a subclass

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Correct Answer:

 Error, private class member can’t be accessed in a subclass

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now