简体   繁体   English

Python 中的私有 Inheritance

[英]Private Inheritance in Python

In python language, all are global by default.在 python 语言中,默认都是全局的。 Same way, inheritance.同样,inheritance。 We can't inherit a base class in private or protected visibility mode.我们不能在私有或受保护的可见性模式下继承基础 class。 But, why is this setup doesn't give that option to inherit with visibility modes???但是,为什么这个设置没有提供继承可见性模式的选项???

Python doesn't do the public/private/protected inheritance of c++. Python 不执行 c++ 的公共/私有/受保护的 inheritance。

It's somewhat a feature of python that you can access anything.这是 python 的一个功能,您可以访问任何内容。 If you want strong encapsulation you have to look at other languages.如果您想要强封装,则必须查看其他语言。

Names beginning with double underscores are effectively private - see Private name mangling .以双下划线开头的名称实际上是私有的 - 请参阅Private name mangling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM