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 inner classes 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 classes" Watch "inner classes" New topic

inner classes

SaiPrasad Jukalkar
Ranch Hand

Joined: Feb 20, 2001
Posts: 79
public class OuterOne{
private int x = 0;
protected class InnerOne{
void amethod(){

public class InSomeOtherClass{
public static void main(String[] args){
OuterOne.InnerOne io = new OuterOne().new InnerOne();
how can InSomeOtherClass has access to protected member class(Inner class)InnerOne.?
according to encapsulation rules, protected member variables or inner classes are accessible only to the derived classes and cannot be accessed outside the class.
can anybody pl. explain me about the above problem

Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

These classes are all in the same package by virtue of having no explicit declared package. No access rules have been violated.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
SaiPrasad Jukalkar
Ranch Hand

Joined: Feb 20, 2001
Posts: 79
i.e we can access the protected variables, if the related classes are in the same package.
I agree. Here's the link:
subject: inner classes
It's not a secret anymore!