• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Defining classes in different files

 
Shikha Upadhyaya
Ranch Hand
Posts: 70
Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should public classes of a single application be defined in separate .java files ?
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
 
Harsha Smith
Ranch Hand
Posts: 287
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harsha - thank you for the good example
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic