Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why private member variable of inner class can't be accessed by its outer class but mehod can be? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

why private member variable of inner class can't be accessed by its outer class but mehod can be?

Divyya Joshi
Ranch Hand

Joined: Jul 15, 2010
Posts: 102
The following code is related to regular inner class and the moment i try to access private member variable of inner class compiler complains error but Not when private member is acessed
Here's the code



Anyone kindly explain this absurd behaviour .
Michael Labuschagne
Ranch Hand

Joined: May 08, 2007
Posts: 56

Divyya Joshi wrote:The following code is related to regular inner class and the moment i try to access private member variable of inner class compiler complains error but Not when private member is acessed
Here's the code



Anyone kindly explain this absurd behaviour .


It's not absurd behavior - on line 7 you have "private x=10;" you have forgotten to set the datatype ... int I presume? Where you have marked error the 'x' has not been declared properly because of what I said in the beginning.

Emre Yurtsever
Greenhorn

Joined: Aug 15, 2011
Posts: 1
Hi Divyya,

It seems that variable type is missing at line 7.

private int x=10;

With this little correction, the code compiles fine.

Hope this helps,
Emre.
Divyya Joshi
Ranch Hand

Joined: Jul 15, 2010
Posts: 102
Oh yeah. Thanks . that was reaaly a very silly mistake of mine.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

Double post of http://www.coderanch.com/t/549815/java-programmer-SCJP/certification/why-private-member-variable-inner , locking


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why private member variable of inner class can't be accessed by its outer class but mehod can be?