• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic