• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism

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




How ???
 
Henry Wong
author
Marshal
Pie
Posts: 21490
84
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
 
Eswar Nec
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
 
Jelle Klap
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:
 
Winston Gutkowski
Bartender
Pie
Posts: 10527
64
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
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python 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