English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

This is not really a drawback of java!
Only one public class is allowed per file in java because
- jvm resloves most things at runtime
If multiple public classes were allowed in one file, and you wanted to create an object of any one of those classes, the java compiler would not know where to look for that class since (theoretically it could be anywhere in the directory in any source file)
So the designers of java decided
- one public class per .java file
- the class name = file name
That way run time look up of a class was deterministic.
Read this if it helps you understand this better
http://www.roseindia.net/javatutorials/manypublicclassesinonefile.shtml

2006-12-19 16:55:01 · answer #1 · answered by Neil 5 · 0 0

java simply does not currently support this.
when you specify the class in a java source file, you are letting the compiler know what to call the source file. if the .java and the class name inside it do not match, it will give you an error. if compiling multiple classes at a time were supported, it would simply write to different files. there is no way to differentiate.

2006-12-19 16:33:38 · answer #2 · answered by Eric J 2 · 0 0

fedest.com, questions and answers