aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner class question 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 "inner class question" Watch "inner class question" New topic
Author

inner class question

Ash Gill
Ranch Hand

Joined: Jun 30, 2011
Posts: 71
here are few i have


scjp k&b book, chapter 8, self test question 8
inner class doubt


this produces output as middle. i understand that, at line 1, the method local class was not yet defined. But why wasn't the outer class A m() method called instead of inner class A's m() method.
Ikpefua Jacob-Obinyan
Ranch Hand

Joined: Aug 31, 2010
Posts: 394

Ash Gil wrote:But why wasn't the outer class A m() method called instead of inner class A's m() method.

Hello Ash...I want to extensively answer your question based on my personal observation...

The 'A' inner class (in my opinion) 'overshadows' the 'A' outer class.
In other to instantiate the outer class and invoke the corresponding m() method, the program has to be created inside a package, and you MUST tell java the fully qualified name of the outer class. Here is a modified version of the program, take note of the package declaration and the modification in line 8 of your program.

Output:

HTH

Regards

Ikpefua


OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
Ash Gill
Ranch Hand

Joined: Jun 30, 2011
Posts: 71
Hi Ikpefua,

thanks a lot.
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206

I've modified the original code to make it works and make sense, if you still have doubt or not clear reread Chapter 8 and check out Java Spec document.

Hope it help....







OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
Tommy Delson
Ranch Hand

Joined: Apr 13, 2011
Posts: 206
Ikpefua Jacob-Obinyan wrote:
Ash Gil wrote:But why wasn't the outer class A m() method called instead of inner class A's m() method.

Hello Ash...I want to extensively answer your question based on my personal observation...

The 'A' inner class (in my opinion) 'overshadows' the 'A' outer class.
In other to instantiate the outer class and invoke the corresponding m() method, the program has to be created inside a package, and you MUST tell java the fully qualified name of the outer class. Here is a modified version of the program, take note of the package declaration and the modification in line 8 of your program.

Output:

HTH

Regards

Ikpefua



The modified code doesn't work, its throw an exception. See below...






Let's me try other approach and see if it works...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner class question