This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inner Class" Watch "Inner Class" New topic
Author

Inner Class

Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Following code works fine, but why isit fails if comment on line 1 is removed and comment on line 2 is added?



"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Rituparno Pal
Greenhorn

Joined: Oct 10, 2004
Posts: 12
Hi
Its simple, can't invoke a inner class constructor unless its not defined. For every class you define a .class file is created by the Java compiler. So when you call the constructor of 'first' class the corresponding can't be found. Its like using a undefined variable.
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Thank you for your reply.

"can't invoke a inner class constructor unless its not defined"
"when you call the constructor of 'first' class the corresponding can't be found."

- Inner class is defined in outer class tst. If you run code as it is, it will compile fine. - So there is no proble of definition of innerclass and it's constructor (which is default).
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
Remember that while instance and class identifiers are in scope throughout the class definition, local method identifiers are only in scope from the point of definition to the end of the method (here I ignore hiding and overriding).

class first is not in scope at line 1 but is in scope at line 2.


Mike Gershman
SCJP 1.4, SCWCD in process
Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
Thank you Mike !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner Class
 
Similar Threads
Question Of The Day !!
One more
throw in finally clause
break statement question
Constructor not executing? Help !!