File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing an object without a reference

 
adithya narayan
Ranch Hand
Posts: 79
Android Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was going through the following piece of code



Is there any other way of accessing the Test object inside the inner class apart from the one mentioned in line #1, if i am creating the Test object from somewhere else and i haven't got a reference to it ?

Thanks,
Adithya.
 
Rituraj tyagi
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I'm also pursuing OCJP and gone through above problem and just extended adithya's example to clear my understanding as follows:-


And got this output :-

Test method invoked in main with innerTest as local from the inner private class
both instance equal

Now what I understand from above this that the line Test test = Test.this got the refrence of the class containing it . Please correct me if I'm wrong.
Thanks

 
Thakur Sachin Singh
Ranch Hand
Posts: 242
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good work
 
Rituraj tyagi
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All I was going through the K & B again and found in 8 th chapter that this syntax is used to refer by inner class to reference the current instance of the outer class. refer page 669.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic