Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class problem

 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1)In here I want to know to get the output as "Body" why we have to apply Body.this.name?please explain this.
2)what code we have to type in getPName () method to get Heart as a output.


 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1)In here I want to know to get the output as "Body" why we have to apply Body.this.name?please explain this.



This is because you want to refer to Body's name. Not Heart's.




2)what code we have to type in getPName () method to get Heart as a output.


This should be simple for you to get. What variable name can you use to make sure the 'name' reference in Heart is made use of ? What have you tried so far ?
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)In here I want to know to get the output as "Body" why we have to apply Body.this.name?please explain this.

we want to refer to the outer class isn't it?
now when we are accessing inner class, then the this reference refers the inner class object
so to access the outer class object we have to write OuterClass.this

2)what code we have to type in getPName () method to get Heart as a output.

Now we want to the member of inner class isn't it?
hence we simply use the this reference

the code is as follows

Hope this helps
hth
happy preparation

[edit] corrected the mistake in the code as per Deepak's suggestion [/edit]

@ Deepak

is this good way to correct the mistakes and editing the posts
I mean writing the edit tag (I have seen this from many good people)
am I contributing neatly?
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad Kharkar wrote:
1)In here I want to know to get the output as "Body" why we have to apply Body.this.name?please explain this.

we want to refer to the outer class isn't it?
now when we are accessing inner class, then the this reference refers the inner class object
so to access the outer class object we have to write OuterClass.this

2)what code we have to type in getPName () method to get Heart as a output.

Now we want to the member of inner class isn't it?
hence we simply use the this reference

the code is as follows

Hope this helps
hth
happy preparation


Prasad your code still uses the outer Body class
 
thejaka samarakoon
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot Prasad
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Deepak

is this good way to correct the mistakes and editing the posts
I mean writing the edit tag (I have seen this from many good people)
am I contributing neatly?


As long as everyone understands the context things are cool.
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Deepak
yes sir
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic