aspose file tools*
The moose likes Beginning Java and the fly likes inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance" Watch "inheritance" New topic
Author

inheritance

vasuma puljety
Ranch Hand

Joined: Jun 01, 2001
Posts: 35
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).]


Sun certified , with the lowest score possible.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
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

Joined: Jul 22, 2000
Posts: 9044
    
  10

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).]


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheritance