Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question 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 "Question" Watch "Question" New topic



Joined: Sep 20, 2000
Posts: 11
class Super
{ int index = 5;
public void printVal()
{ System.out.println( "Super" );
class Sub extends Super
{ int index = 2;
public void printVal()
{ System.out.println( "Sub" );
public class Runner
{ public static void main( String argv[] )
{ Super sup = new Sub();
System.out.print( sup.index + "," );
The result is (5,Sub).Why is not (2,Sub)?Who know reason.
Thank you.
The finally statment execution finish .The rest of the method countinue to run.(True or False)?
chetan nain
Ranch Hand

Joined: Jun 21, 2000
Posts: 159
two points:
1. overridden method called depends on the class denoted by the reference during runtime.
2. shadowed member variable called depends on the type of the reference .
retry your analysis
for your second answer, the data is insufficient to warrant an answer. for example, if an uncaught exception occured, rest of method would be skipped
hth, chetan
I agree. Here's the link:
subject: Question
jQuery in Action, 3rd edition