Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

inner classes mixed with regular classes

 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all.

I've created the code below based in an exercise from K&B SCJP 6.
Looking at the code below, the line marked by "DONTCOMPILE" does not compile because the compiler is trying to use the Zoombie defined in // SECOND.
I'd like to know if there is such a way to use the Zoombie defined in // FIRST.



Thanks!
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Case 1


Case 2

In Case 1 the code given can use Zoombie defined in //FIRST but you need to comment at line 12, 13, 14 because scope influence of class Zoombie is less than inner class Zoombie
In Case 2 you need to create instance of outer class Monsters and then by using instance of Monsters you can create instance of inner class Zoombie because according to Java Language Specification (JLS) non-static variable this cannot be referenced from a static context
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic