Abhi vijay wrote:Edmen, protected members can be accessed in the sub-class only through inheritance. You cannot use an instance of the sub-class to access it( i.e. you cannot use dot operator to access it).
You can use an instance of the subclass to access it, as protected member is now existing in subclass through inheritence.
The trick is you cannot use an instance of the superclass to access it, think protected as private member if accessed outside the package.
If you use
B b=new B();
b.i; then there is no problem.
If you use
A a=new A();
a.i; outside the package of A than i will not be visible outside the package.