This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Doubt with a code Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Doubt with a code" Watch "Doubt with a code" New topic
Author

Doubt with a code

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 973



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

Then why is that the output is
221

Why isnt the 1st value 1 ?


http://www.lifesbizzare.blogspot.com || OCJP:81%
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

"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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Doubt with a code
 
Similar Threads
Try this Qs !!!
Mock trip up question Explained, Shadowing vs Overriding
instanceof operator
Protected in subclasses