File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why is the result?

 
david_chen
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic