| Author |
Polymorphism
|
akila sekaran
Ranch Hand
Joined: Jun 12, 2012
Posts: 48
|
|
How ???
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16681
|
|
akila sekaran wrote:
How ???
My output ...
In Base
In Derived
Henry
|
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
Bartender
Joined: Mar 10, 2008
Posts: 1404
|
|
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
Bartender
Joined: Mar 17, 2011
Posts: 4734
|
|
Jelle Klap wrote:like this:...
Jelle: just a reminder not to put enormously long lines in code blocks
I split yours up.
Winston
|
Isn't it funny how there's always time and money enough to do it WRONG?
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 4089
|
|
|
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.
|
SCJP
|
 |
 |
|
|
subject: Polymorphism
|
|
|