File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Polymorphism" Watch "Polymorphism" New topic
Author

Polymorphism

akila sekaran
Ranch Hand

Joined: Jun 12, 2012
Posts: 48




How ???
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19074
    
  40

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: 1836
    
    7

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: 8427
    
  23

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?
Articles by Winston can be found here
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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
Visit my download page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Polymorphism