4 ms·
This is not how Ruby and Python works, I believe. I guess it's debatable which paradigm JavaScript is more similar to.
by throwaway427 8y ago
This is not how Ruby and Python works, I believe. I guess it's debatable which paradigm JavaScript is more similar to.
- munificent 8y agoPython name-mangles properties that start with "__" to emulate privacy. Run: class Base: def __init__(self): self.__field = 1 def baseMethod(self): print("baseMethod " + str(self.__field)) class Derived(Base): def __init__(self): super().__init__() self.__field = 2 def derivedMethod(self): print("barMethod " + str(self.__field)) d = Derived() d.baseMethod() d.derivedMethod() And it prints: baseMethod 1 barMethod 2 Ruby doesn't really have fields that are private to subclasses, but Ruby also embraces monkey-patching, so that's not entirely surprising.