This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding,Overloading - Question" Watch "Overriding,Overloading - Question" New topic
Author

Overriding,Overloading - Question

Vidyavathi saravanan
Ranch Hand

Joined: Sep 24, 2004
Posts: 34
[CODE]
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();
c.wynyard();
}
public void wynyard(){
Trebble t = new Central();
Base b = (Base) t;
System.out.println(b.i);
}

}
[/CODE}
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: http://aspose.com/file-tools
 
subject: Overriding,Overloading - Question