• Post Reply Bookmark Topic Watch Topic
  • New Topic

Polymorphism  RSS feed

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




How ???
 
author
Marshal
Posts: 23435
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

akila sekaran wrote:



How ???



My output ...

In Base
In Derived



Henry
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi akila,

I test your code. My output is also

In Base
In Derived
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jelle Klap wrote:like this:...


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

Winston
 
Ranch Hand
Posts: 4702
9
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!