File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner classes

 
SaiPrasad Jukalkar
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These classes are all in the same package by virtue of having no explicit declared package. No access rules have been violated.
 
SaiPrasad Jukalkar
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic