aspose file tools*
The moose likes Beginning Java and the fly likes Inner classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inner classes " Watch "Inner classes " New topic
Author

Inner classes

Sid Shankar
Greenhorn

Joined: Oct 10, 2012
Posts: 5
Hi,

This code is from the SCJP study guide with a slight modification. The following code compiles successfully but there is NO output. I was wondering why the statement "Inside getY()" is not generated. Is it because everything inside the local method getY() is erased once out of the method? Still feels like the statement should be output.... Would appreciate any answers.

Thanks in advance.

Sid.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

method-local inner class shouldn't be instantiate outside of that method.


OCA7
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8176
    
  23

Sid Shankar wrote:Would appreciate any answers.

Sid.

I've added code tags to your post, but the indenting is still bad. I'll leave that to you to sort out. Just use the 'Edit' icon.

Please read the UseCodeTags (←click) carefully.

Thanks

Winston
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2359
    
  50
Try adding a call to getX() so the code actually runs.
Sid Shankar
Greenhorn

Joined: Oct 10, 2012
Posts: 5
I have instantiated the class within the method of course. It should give me something because I'm running the method. Tony, I will try calling getX() and see what happens.

Winston, thanks for the tip. Needed to know that.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

Sid Shankar wrote:I have instantiated the class within the method of course.

Do you think that below codes are in getX() ?, these code should be in getX() not outside of that.

InnerClass inner;
inner = new InnerClass();
inner.getY();
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39773
    
  28
Welcome to the Ranch
Please note Winston’s point about indentation. Study guides are often incorrectly indented to confuse you about where a bit of code is. Sort out the indentation and you can easily see whether that code is in the method or not.
Enkita mody
Ranch Hand

Joined: Aug 06, 2012
Posts: 333

I got confused because of your bad code formatting.If you had read Winston tipline then you didn't find it useful to follow it ?

and the mistake is already tony told you.
 
jQuery in Action, 2nd edition
 
subject: Inner classes