This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling two public scope java classes in a .java file

 
Chinmaya Chowdary
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, If I have two default scope classes like(class Test{} and class Test2{}) in a file named it with Test.java or Test2.java, it will compile and why it is not compiling two classes(public class Test{} and public class Test2{}) in a file named it with Test.java or Test2.java, will not compile. Thankyou.
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most compilers have a rule that the name of a public class and the name of the file must be the same (plus .java). You can't get two classes with different names in a file and still have the file with the same name as both. You can't have two classes with the same fully qualified name, so you need two files.
That rule only applies when the classes have public access.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic