aspose file tools
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 OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why is the result?