Hi,
> ...
> I want to know is it logical to call super.go(), when go is actually
> overridden by child class.
Yes, it's a (more or less ;-) common practise. That's what the "super"
keyword is used for (in this context).
The only other possibilty is not very common, IMHO:
class Sub extends Parent {
void go() {
...
}
void bar() {
super.go();
// here it is more common to call this.go()
// but of course this also depends on your use-case
}
}
Ciao,
Ingo
Lew - 26 Apr 2007 22:34 GMT
parkarumesh@gmail.com wrote:
>> I want to know is it logical to call super.go(), when go is actually
>> overridden by child class.
> Yes, it's a (more or less ;-) common practise. That's what the "super"
> keyword is used for (in this context).
[quoted text clipped - 14 lines]
>
> }
Ingo is absolutely right. To provide a little more detail, let's say a parent
(possibly abstract) class provides part of the setup, but wants the child
class to do the rest.
<sscce source="Child.java">
abstract class Parent
{
public void init()
{
System.out.println( "Parent.init()" );
establishConnection();
doMoreParentalGuidance();
}
private void establishConnection()
{
System.out.println( "Parent.establishConnection()" );
}
private void doMoreParentalGuidance()
{
System.out.println( "Parent.doMoreParentalGuidance()" );
}
}
public class Child extends Parent
{
public void init()
{
System.out.println( "Child.init()" );
super.init();
doStuffOnlyChildNeeds();
}
private void doStuffOnlyChildNeeds()
{
System.out.println( "Child.doStuffOnlyChildNeeds()" );
}
public static void main( String [] args )
{
Parent parent = new Child();
parent.init();
}
}
</sscce>
The call to parent.init() will polymorphically call the Child version of
init(), which in turn invokes the Parent version through the super call.

Signature
Lew