Friday, February 15, 2013

Acessing private members of a class in its derived class


Have you ever thought of accessing private members of a class in its derived class ?

The following code will alow you to acess private members of a class in derived classes.


class A
{ 
   private int a = 10;

   class B : A
   {
      public int b = a + 1;
   }

} 

2 comments:

  1. If you really want to build a .NET profile.
    Please get the oops concept correct.

    When you inherit any class , you do inherit the private members and methods BUT you cannot access them in the derived class.

    ReplyDelete
    Replies
    1. I think you missed the concept of the code. It shows that in .net framework by declaring inline class Private Members of parent class are accessible in derived classes.

      Delete