Hai,
class SuperClass
{
int superValue;
SuperClass()
{
System.out.println("Constructor of SuperClass");
this.doValue();
}
public void doValue()
{
this.superValue=555;
System.out.println("superValue= "+this.superValue);
}
}
class SubClass extends SuperClass
{
int value=800;
SubClass()
{
System.out.println("Constructor of SubClass");
this.doValue();
System.out.println("superValue= "+this.superValue);
}
public void doValue()
{
System.out.println("value= "+this.value);
}
public static void main(
String arg[])
{
SuperClass a=new SubClass();
}
}
I found this program in this discussion area.The output of this is
Constructor of SuperClass
value=0
Constructor of Subclass
value=800
superValue=0
After printing "Constructor of SuperClass" ,why is it executing doValue() method of SubClass instead of executing SuperClass's doValue() method.
Can anyone help me at this
Thanks