Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes Polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Polymorphism" Watch "Polymorphism" New topic


akila sekaran
Ranch Hand

Joined: Jun 12, 2012
Posts: 48

How ???
Henry Wong

Joined: Sep 28, 2004
Posts: 20370

akila sekaran wrote:

How ???

My output ...

In Base
In Derived


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Eswar Nec
Ranch Hand

Joined: May 02, 2010
Posts: 105
Hi akila,

I test your code. My output is also

In Base
In Derived

Wake up! Don't let your smile be snatched away by anybody!
Regards, Eswar
Jelle Klap

Joined: Mar 10, 2008
Posts: 1949

Are you sure this is the exact code, copied and pasted directly from the .java file?
I could imagine the code you're actually running has a typo or character case difference in the method name in the Derived class, which would mean it's not actually an override of the Base calss' method.
To avoid situations like that it's very usefull to tag a method that is intended to be an override (or interface implementation as of Java 6) with the @Override annotation, like this:

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8837

Jelle Klap wrote:like this:...

Jelle: just a reminder not to put enormously long lines in code blocks
I split yours up.


Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

it has happened to me before. perhaps when you compiled you compiled the "main" class and assumed it would also recompile a class it depended on, but there was already a class file by that name so it didn't recompile the helper class.

Visit my download page
I agree. Here's the link:
subject: Polymorphism
It's not a secret anymore!