| 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: 1778
|
|
|
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: 1778
|
|
|
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: 32830
|
|
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: 1778
|
|
|
Harsha - thank you for the good example
|
 |
 |
|
|
subject: Defining classes in different files
|
|
|