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

Question on parent-child members  RSS feed

 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question

parent class has a member String test = "parent";

child class has

String test = "child";

i instantiate a child class instance with parent class reference in some third class

what will the child class instance have in its test member varible? when i access the member in parent class member method (USing this reference) and when i access the member in child class method method ((USing this reference))
???
 
Deepak Jain
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood !

Answer: The instance will have both the members so it will have two members test="parent" and test="child" and depending on the class where its accessed the value will be so. If accessed from parent class member method as this.temp, here temp would point to "parent" member and if accessed from child member method it will point to child class member method and hence have the value "child".



  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!