Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange o/p.Polymorphism in Overrided method?

 
Micheal John
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


For the above pgm, how the o/p is: AAA

In all the three classes m1 has been overrided and polymorphism will come to play. so the below line
A3 a4 = new C3();
ref var is A3 and resolved at compile time, but while run time it has to call the C3 object's m1() only.. how it's calling A3 object's m1()?
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notice there is no overriding because the methods do not have the same signatures.
 
Satish Kota
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not overriding you are overloading the methods. And which methods to be called will be determined by the referenced type
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic