This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Question" Watch "Question" New topic
Author

Question

Hans
Greenhorn

Joined: Sep 20, 2000
Posts: 11
1)Question
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 + "," );
sup.printVal();
}
}
The result is (5,Sub).Why is not (2,Sub)?Who know reason.
Thank you.
2)Question
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: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Question
 
Similar Threads
Instance Variables
Casting
Class/Sub Class
mock exam question need some help
Use of constructor in abstract class?