• 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, S G Ganish Tushar Sharma book

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In page 98 of "Oracle certificated Professional Java SE7 programming Exams 1Z0-804 and 1Z0-805" by S G Ganish Tushar Sharma(2013), the authers claim that we can not use . I used it in the example written in the same page and it compiled and ran without errors. I could not find about this in the errata supplied by the auther(Ganish) on his blog.
The argument in the beginning of page 99 is true for the reference from outside the outer class so no need to refer to the use of this before the new.
I needed to create an instance of the outer class Circle to instantiate the inner class Point only when I am outside Circle, like this .
Is there any explanation please.
 
Ranch Hand
Posts: 175
17
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I agree. It doesn't make sense since "this" is implicit.

If Point is an inner class in Circle, and Point is instantiated in a Circle constructor, there is no difference between:

Point center = new Point(x, y); // instantiate Point in the context of the current instance of Circle

Point center = this.new Point(x, y); // instantiate Point in the context of the current instance of Circle

Point center = Circle.this.new Point(x, y); // instantiate Point in the context of the current instance of Circle

You can post problems on their errata page.
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic