The above form of declaration is correct But you should note that the Foo class does not contain doBarStuff() method
The Bar class is extending the contents of the Foo class Mean, the Bar class is extending the doFooStuff() method
But, the Foo class does not extends the Bar class or the doBarStuff() method mentioned in Bar Class
It works if you write
f.doFooStuff() instead of f.doBarStuff() as the Foo class contains doFooStuff() and is already inherited by Bar Class Hence, is also not altered It works
If you don`t want to alter the code, add a method name doBarStuff(),with void type in Foo class and make a try.
[ August 19, 2008: Message edited by: Pradeep Balasubramanian ]
Regards,<br />Pradeep Balasubramanian<br /> <br />You have to grow from the inside out. None can teach you, none can make you spiritual. There is no other teacher but your own soul. <br /> <br />- Swami Vivekananda
Actually my idea is that we are creating the bar object here (which is a subclass of Foo) with the help of base class reference Foo f so i thought we can Invoke the subclass bar's method doBarStuff() with the base class reference Foo f.
Well where have i gone in my interpretation ? [ August 19, 2008: Message edited by: sri dev ]
you can invoke a subclass methode using a super class reference if the methode is already present in super class and its overridden. superclass doesn't have an idea of subclass method if its a new method. A method is invoked on the basis of reference type used not the object type created at runtime.