• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java concepts

 
Abhishek kumar Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why there can be only one public class in a source code file?

 
fred rosenberger
lowercase baba
Bartender
Posts: 12084
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has been asked many times in this forum. You may want to try searching for more details, but the short and simple answer is because it makes writing the compiler easier.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There can be only 1 public upper level class in a .java file because javac references the file by the name for compiling when delared public. The .java file containing the public class must have the same name as that of the class. Moreover, a file can have only 1 name, so only 1 public class

But there can be any number of inner public classes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic