GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes why do we have atmost one public class in a source file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why do we have atmost one public class in a source file " Watch "why do we have atmost one public class in a source file " New topic
Author

why do we have atmost one public class in a source file

divyasheel sharma
Greenhorn

Joined: Feb 15, 2001
Posts: 19
Dear friends,
Pls explain me why do we have only one public class atmost in a source file and why the class name shall match the unextended file name, is this a convention? Why?
Rgds
Divya

------------------
Eat Java,Drink Java...surf only Javaranch!


Eat Java,Drink Java...surf only Javaranch!
Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
Hi Divya,
The reason for this is to force a coding convention onto programmers. If you are looking at somebody else's source, then all you should be interested in is the public classes. If the public classes are in files of the same name, its easy to find them. I believe thats the the theory anyway...

------------------
- Daniel


- Daniel
divyasheel sharma
Greenhorn

Joined: Feb 15, 2001
Posts: 19
Thanks Daniel!
-Divya
------------------
Eat Java,Drink Java...surf only Javaranch!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: why do we have atmost one public class in a source file