Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Other class

 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when should we do and what is the diff
public class A
{
public class B;
}
and
public class A
{
private class B;
}
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The public classes in a package are intended to be used by classes in other packages. The non-public classes are not. Similarly, public nested classes are intended for use by code in other packages, while private nested classes are intended to be used only by the containing class.
The "used by code in other packages" stuff might be slightly confusing; if you're used to thinking of student programs that consist of only one class, it's meaningless. But "real" software often contains thousands of classes; structuring them into packages makes the program comprehensible, and hiding most of the classes as non-public classes makes the relationships between the packages much clearer.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, aakash, you might want to take a look at Sun's Java Tutorial on Access Control.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic