wood burning stoves 2.0*
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
Author

inner classes

SaiPrasad Jukalkar
Ranch Hand

Joined: Feb 20, 2001
Posts: 79
public class OuterOne{
private int x = 0;
protected class InnerOne{
void amethod(){
System.out.println("xyz");
}
}
}

public class InSomeOtherClass{
public static void main(String[] args){
OuterOne.InnerOne io = new OuterOne().new InnerOne();
io.amethod();
}
}
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


JSP
Michael Ernest
High Plains Drifter
Sheriff

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: http://aspose.com/file-tools
 
subject: inner classes
 
Similar Threads
inner classses
Inner Class
Inner and outer class instances
inner class.... verifyError.
"this "of inner class