wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why is the result? 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 "why is the result?" Watch "why is the result?" New topic
Author

why is the result?

david_chen
Greenhorn

Joined: Jun 28, 2001
Posts: 3
code:
class Base {
int i=99;
public void amethod(){
System.out.println("Base.amethod()");
}
}
public class RType extends Base{
int i=-1;
public static void main(String argv[]){
Base b = new RType();//<= Note the type
System.out.println(b.i);
b.amethod();
}
public void amethod(){
System.out.println("RType.amethod()");
}
}

the irght answer is :
99
RType.amethod()
why not is :
-1
RType.amethod()
or
99
Base.amethod()
please help me!!
anand raman
Ranch Hand

Joined: Jun 06, 2001
Posts: 66
david this question has been discussed endlessly even in a post around 2 days back. Please check the archives for "HOW VARIABLES ARE DECIDED" posted by ZEESHAN AZIZ on June 24.
Hope this helps
Anand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why is the result?
 
Similar Threads
Help with this one from Markus Green's mock exam
Overloading(why the answer is b, but not c
Upward Casting _ doubt
question from Marcus Green's website tutorial
Why superclass reference invokes subclass method