• Post Reply Bookmark Topic Watch Topic
  • New Topic

public class in own file?  RSS feed

 
Pieter-Jan Delaruelle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently trying to compile and run the example from p.39-40
in the head first book.
But when I try to compile, it gives 2 errors about the public classes needing their own file. How do I go about doing this?
Or if anyone is familiar with the book, can I just go ahead and pick it up later?
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pieter-Jan wrote:
But when I try to compile, it gives 2 errors about the public classes needing their own file. How do I go about doing this?



Ola rancheros!

Rules are:
If no class is public, a .java file can have any number of classes, and the .java file can have any name.

If one class is public (maybe among other classes with default access), the .java file's name must be the same as the public class's name.

There will be no compile if a .java file contains more than one public class.



No rule, but better to do:
one class one file

Because when you got an error, the compiler will refer to the .java file. When a whole bunch of classes is in this file, it's up to you to find out.


Yours,
Bu.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!