Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt with a code

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


//super.over should call variable of alpha 1st shouldnt it?

Then why is that the output is
221

Why isnt the 1st value 1 ?
 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"super" in super.over only "points up" one class. Since the current class is Gamma that means that super.over means Beta's over - 2.

As for why b.over and a.over are 2 and 1 respectively (in case you don't know): fields (and static methods) are not subject to the rules of polymorphism; the reference type (Beta and Alpha respectively) determine what field (or static method) to use.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic