File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes how to access protected inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to access protected inner class" Watch "how to access protected inner class" New topic
Author

how to access protected inner class

Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
the code below is a class in one package



now my question is , how to create an object of the inner class which has access type protected ( as seen in above example ) in some other package ? I tried code as seen below but didn't worked , please help.....



this also didn't worked



please solve my doubt
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Well, let's see if you can solve it. It usually helps if you read the error message. For example, here is the code I used to test:


When I tried to compile Maker, this is the error message:


The error message tells you that Inner() [That's the Constructor for the Inner class] has protected access, which means, since Maker does not extend Inner, it can not access Inner() [and therefore can't make a new instance of the Inner class].

There are two solutions to this problem, one involves changing Inner slightly, the other involves adding a new class (inside Maker). Can you come up with the solutions?


Steve
Rahul Shivsharan
Ranch Hand

Joined: Jun 17, 2009
Posts: 83
i got it , please go though it


Parent class in a package which has the inner class with access type protected



the child class in other package



the above code compiles and runs , but what about the first solution you wrote about modifying the inner class which is in parent class , this i didn't understood
can you please elaborate on this hint
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

You can add a public constructor to the inner class.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Hardly a beginning question. Moving thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to access protected inner class