File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding,Overloading - 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 "Overriding,Overloading - Question" Watch "Overriding,Overloading - Question" New topic

Overriding,Overloading - Question

Vidyavathi saravanan
Ranch Hand

Joined: Sep 24, 2004
Posts: 34
class Trebble{
int i = 99;
class Base extends Trebble{
int i =100;
public class Central extends Base{
public static void main(String argv[]){
Central c = new Central();
public void wynyard(){
Trebble t = new Central();
Base b = (Base) t;

1 Compile time error
2 Compilation and output of 99
3 Compilation and output of 100
4 Compilation, but runtime error because an instance of Trebble cannot be cast to type Base

The Correct Answer is 3).This is on what basis?
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Variables are referred by type of reference variable and not type of object referred to.

In this case, type of reference variable is b. Value of i in b is 100

"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
I agree. Here's the link:
subject: Overriding,Overloading - Question
It's not a secret anymore!