Dynamic method lookup

Hi all

Here is my code:

class Superbase{void print(Superbase s){System.out.println("Super");}}

class Baseextends Superbase{void print(Base b){System.out.println("Base");}}

class Derivedextends Base{staticvoid print(Derived d){System.out.println("Derived");}}

class OverloadDemo{

publicstaticvoid main(String[] args){

Superbase a =new Superbase();

Superbase b =new Base();

Derived c =new Derived();

a.print(new Superbase()); b.print(new Base()); c.print(new Derived());

}

}

a,b,c denore objects of Superbase, Base, and Derived classes respectively. According to me it should print "Super Base Derived". But, it's printing "Super Super Base"

can you explain ....why is it so?

Thanks

[1908 byte] By [ramkria] at [2007-11-26 22:31:35]
# 1
are all the methods static or just the last one? (i.e. a typo in your post)
-Kayaman-a at 2007-7-10 11:37:15 > top of Java-index,Java Essentials,Java Programming...
# 2
only the last method is static. There're no errors in the code.
ramkria at 2007-7-10 11:37:15 > top of Java-index,Java Essentials,Java Programming...