// Super.java
package p1 ;
public class Super {
protected void say (
String s ) {
System.out.println ( s ) ;
}
}
// SubOne.java
package p1 ;
public class SubOne extends p1.Super { }
// SubTwo.java
1. package p2 ;
2. public class SubTwo extends p1.Super {
3. public static void main ( String [ ] args ) {
4. p1.Super s = new p1.Super() ;
5. p1.SubOne s1 = new p1.SubOne () ;
6. SubTwo s2 = new SubTwo() ;
7. s.say (" Super ") ;
8. s1.say ("SubOne") ;
9. s2.say ("SubTwo") ;
10. }
11. }
On compile the code we get compile time errors at statements 7 and 8 .... according to me the errors are because we are trying to access say() through the reference of the super class !!
While the concept says that a protected member can be accesed only via the reference of the child class (SubTwo ) or any of its subtypes....
Please let me know if i am wrong !!
Thanks