This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Variable hiding  RSS feed

 
lu v thuan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends

I think the result is :15 , 15
Am i wrong, if so pls make it clear to me?
Thank in advanced
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is 15 and 5.
The cast you have made here ((A)bobj))is equivalent to assigning a base class reference to a superclass type. Hence the i in the superclass gets invoked. Do take a look at this modified code and run it...it might help.

HTH
Shyam
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!