Forums Register Login

Doubt with a code

+Pie Number of slices to send: Send


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

Then why is that the output is
221

Why isnt the 1st value 1 ?
1
+Pie Number of slices to send: Send
"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.
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 817 times.
Similar Threads
Mock trip up question Explained, Shadowing vs Overriding
Try this Qs !!!
Protected in subclasses
instanceof operator
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:51:00.