Encapsulation in python - What would be the output of the following code?

320
1
03-24-2022 06:39 AM
rraahhaaddii09
New Contributor

Wanted to understand what would be the output of this code:

 

class BaseClass:
    def __init__(self):
        self.a = "GoForGyan"
        self.__c = "goforgyan"

    def display(self):
        print(self.a,self.__c)


class Derived(BaseClass):
    def __init__(self):
        BaseClass.__init__(self)
        print(self.__c)


obj1 = BaseClass()
obj1.display()

 

Thank You!

Tags (1)
0 Kudos
1 Reply
JohannesLindner
MVP Frequent Contributor

Hey, welcome to the ESRI community!

This is a forum specifically for all GIS products of ESRI. If you have nothing to do with that and only have questions about Python, this might not be the best place to ask.

 

What will be the output? Well, have you tried to run it?

You create a BaseClass object and run its display() method. This method prints two attributes (a & __c) of the object. You don't do anything with the derived class.

The output will be "GoForGyan goforgyan".


Have a great day!
Johannes
0 Kudos