No offence, but Anil is incorrect. You can have as many classes in one program as you want. The reason you can only have only one public class is because the public class name is the same as the source file name. Of course you can't have two source files with the same name in your source directory. Otherwise the public class and the rest of the classes in your program are no different in terms of status or ability.
In this program, you have two seperate and individual classes;
_______________________________________________________________
public class TestIt {
public static void main(String stuff[]) { //program starts here
OtherClass OC = new OtherClass(); //create object
}
}
class OtherClass {} // do nothing
_____________________________________________________________
When you compile the above, you must name the source file TestIt.java, because that's the name of the public class. The
compiler will create two class files; TestIt.class & OtherClass.class. These two will be used (interpreted) by the JVM when you run the program.
Here's a program with an inner class, named InnerClass;
____________________________________________________________
public class TestIt {
public static void main(String stuff[]) { //start to run here
OtherClass OC = new OtherClass(); //create object
class InnerClass {} // do nothing
}
}
class OtherClass {} // do nothing
____________________________________________________________
This class is subordinate to TestIt,unlike OtherClass. When you compile the above program, you get the two original class files, along with this one: TestIt$1$InnerClass.class. You can see by the name that this class has an inherent dependency on the outer class.
If you really want to get a good grasp of all of this, I'd recommend either of the following excellent books: Programmers Guide to Java Certification (Mughal-Rasmussen) or The Complete Java Reference (LOTS of great fundamental exercises) by Naughton-Schildt.
Have fun and let me know if I can help

------------------