What am I missing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What am I missing?

I'm learning about encapsulation and need to use a protected and private variable. When I run it, it tells me "protected() is undefined" I know it's probably the smallest thing, but can't quite figure it out, any help would be appreciated. class User:      _name = ""      __id = 0        def Info(self, _name, __id):          self._name = _name          self.__id = __id          def protected(self,User):         self._name = "Peaches"             def Private(self):          self.__id = 1234        def getPrivate(self):          self.__id = 0          print(self.__id)        def setPrivate(self, id):          self.__id = id     obj = Protected() obj.getPrivate() obj.setPrivate(1234) obj.getPrivate()  

12th Dec 2021, 3:31 PM
Nathan Crawford
Nathan Crawford - avatar
2 Answers
+ 1
protected() is a method, not a function. So you have to create an instance of the User class first and then call its method.
12th Dec 2021, 3:39 PM
Simon Sauter
Simon Sauter - avatar
0
I see now, thank you so much!
12th Dec 2021, 6:19 PM
Nathan Crawford
Nathan Crawford - avatar