• Post Reply Bookmark Topic Watch Topic
  • New Topic

package  RSS feed

 
Ankit Neekhra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we create user define package. in this package we define several classes
my question is which name we should save the program
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You save the classes in files with their names. You can save them in a .src (for source) folder, or (probably better) in folders matching the package hierarchy. The Java Tutorials might help you.
 
Sunil Sunny
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to this Forum
If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . Hope this will also help you.
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil Sunny wrote: Welcome to this Forum
If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . Hope this will also help you.

Are you talking about single file? Ideal practice is - create a different file for each class. That way, it becomes easy to maintain the application.
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil Sunny wrote: Welcome to this Forum
If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . Hope this will also help you.

If you are having muliple classes in single file you are not required to must have a public class. All classes can have default access modifier.
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunil Sunny wrote: . . . If your program contains more than one classes . then you must only declare one public class only and name save that with your publiclassname.java . . . .
Not quite accurate; the other two people posting have given the correct answers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!