Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inheritance

 
vasuma puljety
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While doing some examples in Marcus Green's site I have encountered this one.

class Base {
int i=99;
public void amethod(){
System.out.println("Base.amethod()");
}
Base(){
amethod();
}
}
public class RType extends Base{
int i=-1;
public static void main(String argv[]){
Base b = new RType();
System.out.println(b.i);
b.amethod();
}
public void amethod(){
System.out.println("RType.amethod()");
}
}

When I ran this I thought(Even Green said) the output would be
RType.amethod
99
RType.amethod
But the output I got on my machine is
99
Base.amethod
Any clues?
vasuma

P.S: I have JDK 1.3.1. on my machine.


[This message has been edited by vasuma puljety (edited November 24, 2001).]
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the output expected just fine. You sure you put in everything correctly? I just did a cut and paste of your code and worked.
Jason
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

When I ran this (cut and paste) the output was:

RType.amethod
99
RType.amethod

I also have JDK 1.3.1. on my machine.

[This message has been edited by Marilyn deQueiroz (edited November 24, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic