Why is there no compile error in c. Isn't the protected member m2() accessed by creating an instance and not by inheritance? I am confused as to how the protected members can be accessed.
That code above will compile fine because C already inherited the public and protected properties of A. So it is legal to call method m2().
The first code you have mentioned is different from the 2nd one because from there you instantiated your superclass ModifierTest in your Test class (this is not inheritance) and tries to access the protected member, definitely it will not compile. The Dan's mock exam will compile fine because the superclass A was
not instantiated...it was inherited and then it creates an instance of C in order to call the method m2() inherited from A. You need to instantiate C because you are in a
static method (main method).
On the other hand, i do agree with the above explanation of Murtuza.
[ August 13, 2004: Message edited by: arnel nicolas ]