This week's giveaway is in the Groovy forum.
We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line!
See this thread 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 Groovy Fundamentals video training course this week in the Groovy forum!
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."
Consider Paul's rocket mass heater.
subject: Overriding,Overloading - Question