This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using Other class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using Other class" Watch "Using Other class" New topic

Using Other class

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
when should we do and what is the diff
public class A
public class B;
public class A
private class B;
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

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.

[Jess in Action][AskingGoodQuestions]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Also, aakash, you might want to take a look at Sun's Java Tutorial on Access Control.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
subject: Using Other class
Similar Threads
My first interface
inner class ?!
Class and Java file
Two public classes
Want to extend Console.