-2

In python language, all are global by default. Same way, inheritance. We can't inherit a base class in private or protected visibility mode. But, why is this setup doesn't give that option to inherit with visibility modes???

  • 3
    No it is not possible. If you want to use functionality of class A in class B without making B a subtype of A, consider composition instead of inheritance. – khelwood Aug 05 '20 at 10:52
  • 1
    Since Python has metaclasses, you can fully customise what a class is or how it is constructed, including what it means to inherit from another class. So yes, "it is possible". Whether you should actually *do* that, or whether you actually *want* that instead of something else is hard to tell. Can you please [edit] your question to clarify what you need (e.g. in terms of desired syntax or desired behaviour) to show volunteers that the effort to sketch a solution is a) correct and b) desirable? – MisterMiyagi Aug 05 '20 at 11:00
  • 1
    Please don't just edit your question into a completely new one. If you have a new question, post it as a separate question. – MisterMiyagi Aug 20 '20 at 09:37
  • Is [this](https://stackoverflow.com/q/17160162/12500840) answer your question? – ClassHacker Aug 20 '20 at 09:44

2 Answers2

1

Python doesn't do the public/private/protected inheritance of c++.

It's somewhat a feature of python that you can access anything. If you want strong encapsulation you have to look at other languages.

Carlos
  • 5,991
  • 6
  • 43
  • 82
-2

Names beginning with double underscores are effectively private - see Private name mangling.

brunns
  • 2,689
  • 1
  • 13
  • 24