i compiled and run this simple programm and got strange output.
pls check
*************************
//Downcasting of object reference
class sup
{
int supvar=5;
protected int meth()
{
System.out.println("Super class method");
return 1;
}
}
class k27 extends sup
{
public int meth()
{
System.out.println("Sublcass method(overridden) called");
return 2;
}
public static void main(
String args[])
{
k27 sub=new k27(),sub2;
sup sobj=new sup(),sobj2;
sobj2=sub;
sub2=(k27)sobj2;
System.out.println("superclass var invoked via super reference: "+sobj2.supvar);
System.out.println("sobj2.meth()"+ (sobj2.meth()));
System.out.println("sub2.meth()"+ (sub2.meth()));
}
}
*********************
the out put of this program at my computer is :
superclass var invoked via super refernce: 5
subclass method(overridden) called
sobj.meth()2
subclass method(overridden) called
sobj.meth()2
I am unable to understand why the string "sobj.meth()" doesn't prints before the print stmt. in the method .