aspose file tools*
The moose likes Beginning Java and the fly likes Defining classes in different files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Defining classes in different files" Watch "Defining classes in different files" New topic
Author

Defining classes in different files

Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

Should public classes of a single application be defined in separate .java files ?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Yes. Else you will get an error. So if you have 10 classes that are declared public, you will end up with 10 java files.
Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70

John Jai wrote:Yes. Else you will get an error. So if you have 10 classes that are declared public, you will end up with 10 java files.


Oh ok thanks Is there any specific reason for the same?
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
See this recent thread - http://www.coderanch.com/t/555184/java/java/Why-name-public-class-should
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
The answer is yes and no

yes....for the inner public classes defined inside the top class file

no....for the classes defined outside the class that was defined in its own file(class name and file name are the same)
Shikha Upadhyaya
Ranch Hand

Joined: Aug 17, 2011
Posts: 70


Thanks

Harsha Smith wrote:The answer is yes and no

yes....for the inner public classes defined inside the top class file

no....for the classes defined outside the class that was defined in its own file(class name and file name are the same)

Oh thanks. Good piece of information.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38896
    
  23
Harsha Smith wrote:The answer is yes and no

yes....for the inner public classes defined inside the top class file

no....for the classes defined outside the class that was defined in its own file(class name and file name are the same)
Are you sure you have “yes” and “no” the right way round?
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Harsha - thank you for the good example
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Defining classes in different files