Monday 23 December 2013

What should be remember while dealing with Protected data member in child class?

I give one example .

class parent
   {
       protected int a;
   }
   class child : parent
   {
     
       void fun()
       {
           parent p = new parent();
           p.a = 10; //Error Cannot access protected member through parent object
           a = 10; //NO error .We can access protected member through inheritance hierarchy.
       }
   }

No comments:

Post a Comment