• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inner class problem

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot Prasad
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Deepak
yes sir
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic