File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes method-local inner class problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "method-local inner class problem" Watch "method-local inner class problem" New topic

method-local inner class problem

Juwonlo Ibigbami
Ranch Hand

Joined: Nov 03, 2006
Posts: 83
please, given a method-local-inner-class, what will happen to the class if the method is called from with the class
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274

This example cause a stack overflow. Can you see why?


all events occur in real time
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383

Refer above code. Your doubt will be clear.

You can call enclosing method from within that method's inner class, it is legal, your code will compile. But as you know we cannot access local variables of enclosing method from method-local inner class then why you need to invoke that method from the class.

When I ran this program I got output like this.
"enclosing method".
-Looks like code doesn't go into the method-local inner class. That's why it doesn't print "inner class method".

Anybody have any idea?

SCJP-1.5<br />SCWCD-1.4
ranjitsingh thakurratan

Joined: Jul 25, 2007
Posts: 18

Dolly, there wasn't any inner class instance created and a method called..hence the inner class never got executed.

from with in the method local inner class call Inner x = new Inner();

Juwonlo Ibigbami
Ranch Hand

Joined: Nov 03, 2006
Posts: 83
Thanks to you all, what of if the method was called insede the outer class?
I agree. Here's the link:
subject: method-local inner class problem
It's not a secret anymore!