File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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
 
 
subject: Question
 
Similar Threads
Use of constructor in abstract class?
mock exam question need some help
Class/Sub Class
Instance Variables
Casting