• 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

Sybex OCP Java 8 Study Guide Chapter 1 seemingly wrong statement regarding accessing an inner class

 
Greenhorn
Posts: 8
1
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am referring to Sybex OCP Study Guide for IZO-809 , Chapter 1 , Topic Inner Classes. Quoting some text from the below code's explanation "Line 15 uses the awkward syntax to instantiate a B. Notice the type is A.B. We could have written B as the type because that is available at the member level of B. Java knows where to look for it".  However as per my understanding we are accessing B from static method, and hence directly using B as reference type will not work as it is not a static inner class. Please let me  know if my understanding is correct

 
Ranch Hand
Posts: 33
Android Netbeans IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand you right you want to use Type B instead of type A.B. You can use type B always if you are in class A because class B is in class A. That is independent of static context.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben is correct. To use an instance of the class is different than referring to the class by name.
 
Maxitoxin Mayank
Greenhorn
Posts: 8
1
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben, though to further clear my understanding, if we replace the statement with it will fail to compile in the current context, isn't it?
 
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maxitoxin Mayank wrote:Thanks Ben, though to further clear my understanding, if we replace the statement with it will fail to compile in the current context, isn't it?


I don't think so because both A.B b = a.new B(); and B b = a.new B(); means same. It compiles and runs successfully.
 
Ganesh Patekar
Bartender
Posts: 1251
87
Hibernate jQuery Spring MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way It's main not Main and method name is allTheX() not getAllX();  
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic