Does C# have the notion of private and protected inheritance?

前端 未结 10 1054
执笔经年
执笔经年 2020-12-16 09:02

Does C# have the notion of private / protected inheritance, and if not, why?

C++


class Foo : private Bar {
 public:
   ...
 }; 
         


        
10条回答
  •  天涯浪人
    2020-12-16 09:44

    @bdukes: Keep in mind that you aren't truly hiding the member. E.g.:

    class Base
    {
       public void F() {}
    }
    class Derived : Base
    {
       new private void F() {}
    }
    
    Base o = new Derived();
    o.F();  // works
    

    But this accomplishes the same as private inheritance in C++, which is what the questioner wanted.

提交回复
热议问题