aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JRE corrupted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JRE corrupted" Watch "JRE corrupted" New topic
Author

JRE corrupted

rahul kumar
Ranch Hand

Joined: Feb 24, 2001
Posts: 75
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 .
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You were expecting it to print the sobj2.meth() String BEFORE it knows WHAT to print? Before it knows the outcome of the call to the method?
That would be fairly amazing.
Expressions and statements are evaluated and resolved before executing.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Rashmi Hosalli
Ranch Hand

Joined: Jun 25, 2001
Posts: 50
Cindy,
I agree with you...but I wanted to know why the return value appears in the end after both the statements are printed out.Could you please explain?
Thanks,
Rashmi
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Rashmi,
The sub2.meth() call has to be evaluated to see what needs to be concatenated to "sub2.meth()". The string gets built and then printed. It doesn't print the first part, evaluate and print the second part.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JRE corrupted