Why are my privates accessible?

后端 未结 5 865
温柔的废话
温柔的废话 2021-01-19 05:47

I have the following code:

public class PersonInitializer
{
    private Person _person;

    public static Person LoadFromFile(string path)
    {
        Per         


        
5条回答
  •  清歌不尽
    2021-01-19 06:09

    In C# (and Jave, C++) the scope of a field is based on the class, so all instances of the class can access private members of other instances of the same class.

    In languages like Eiffel (and Smalltalk) the scope of a field is based on the instance, so a private field can only be access by the same instance. The Eiffel method may be better, but C++ won the hearts and minds of most programmer, hence very few people question “class based scopeing”

提交回复
热议问题