title: Accessing inherited private base class member...through derived class object...created in base class member
body: <p>I can't wrap my head around why m() in class a can access x and y through the b class and  b class object if x and y are private. I know that when b inherits from a, b receives private members from a even though they can't be used by b. But what is strange to me is that b members can't use x and y, and classes other than a can't get at the variables through b class and  b class object, yet m() can access x and y through the b class and b class object.</p>
  
  <p>Can someone explain this to me using a general rule that I missed or maybe an explanation about how the compiler does this 'giving' of base members to derived classes?</p>
  
  <pre><code>class a
  {
      private int x;
      private static int y;
  
      static void m()
      {
          b bobj = new b();
          int mm = bobj.x;
          int rr = b.y;
  
  
      }
  
      void n()
      {
          b bobj = new b();
          int mm = bobj.x;
          int rr = b.y;
      }
  }
  
  class b : a
  {
      private int u;
      private static int v;
  
      static void o()
      {
  
      }
  
      void p()
      {
  
      }
  }
  </code></pre>