• Post Reply Bookmark Topic Watch Topic
  • New Topic

can we achieve runtime polymorphism by data members?  RSS feed

 
Sumant Mehta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we achieve runtime polymorphism by data members?
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sumant,

"Runtime polymorphism" isn't a phrase that is used much. I think you mean "overriding". If so, and if by "data members" you mean "fields", then no, you can not override fields.

What would it even mean to override a variable?
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you cannot override fields. you should not even try.Now you have two different values for i, and you cannot say that a Sub is‑a Super.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Now you have two different values for i, and you cannot say that a Sub is‑a Super.

You can even write:although these days, the compiler will usually issue a warning when you're "hiding" things - because (@Sumant) that's what you're doing.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!