File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes private inner class access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "private inner class access" Watch "private inner class access" New topic
Author

private inner class access

Viktor Kubinec
Ranch Hand

Joined: Jan 28, 2012
Posts: 34
Given this code:


Why //1 compiles? Is it ok that this statement returns object of Type which is not acessible from this place?
Why //3 compiles (and prints "I AM HERE" , which means that toString method was accessed)
I understand why //2 doesn't compile, I just put it here to show that toString method cannot be called here.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Viktor Kubinec wrote:Given this code:


Why //1 compiles? Is it ok that this statement returns object of Type which is not acessible from this place?

Yes, it's fine. All that matters is that A, newA(), and A.lala() are accessible. It's very common to do this. For instance, I think some Collections' iterator() methods return instance of private Iterator implementations.

Why //3 compiles (and prints "I AM HERE" , which means that toString method was accessed)


Because println(Object) calls some other methods, which eventually end up calling Object.toString(), which is accessible.

I understand why //2 doesn't compile, I just put it here to show that toString method cannot be called here.


The difference is that //3 is println(Object), but //2 gives a reference to the inaccessible B type. If you change that to


then it will compile.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private inner class access
 
Similar Threads
Is System.out.println method calling toString() by default? A strange behavior.
garbage collection doubt
Overriding Private Methods
garbage collection
Collections - Linked list