The code is giving Compiler Error because the method say() in Super is available to SubTwo & SubOne via inheritance though its access is protected. So you do not need any reference to access them, they can be access just be their name.
Originally posted by Harshit Rastogi: Hi The line 7 and 8 gives error because you can acces a protected method only via class which has inherited it and not by directly creating a object of a class in a different package.
Let me rephrase it The line 7 and 8 gives error because you can acces a protected method only via class object (SubTwo) which has inherited it and not by directly creating a object of a class directly (Super, SubOne)in a different package.
[ September 12, 2008: Message edited by: Paul Somnath ]
Hi Paul, Thanks for the explanation. I had already gone through the website as well as the K&B.
However they have both mentioned accessing variable in the Parent class- which has not been re defined in the child class.
If i have defined a say() method in all the three classes - Super,Subone and SubTwo Or a variable s in all the three - that case how do I call the variable or method in Super or SubOne class because it will always give the value of SubTwo.I mean is it even possible!? [ September 12, 2008: Message edited by: Nabila Mohammad ]
The future belongs to those who believe in the beauty of their dreams.Dream BIG!