Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes HF Java 2ed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HF Java 2ed" Watch "HF Java 2ed" New topic
Author

HF Java 2ed

marc valente
Greenhorn

Joined: May 24, 2007
Posts: 1
Hello I am new to java. I am reading HF java and trying to compile code form chapter 2 but i am runing into truble. I am trying to run the Guessing Game code but i get errors saying that the public class for the 3 difernt classes i.e player, GameLunch and GuesGame should be in diferent files and not on the same file. Not sure what to do.


thanks,
marc
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Welcome to the Ranch.

This is a rule most compilers impose; if you have three public classes called Player, GameLunch and GuessGame, you need three source files with the same names and ".java" extension, ie Player.java, GameLunch.java and GuessGame.java.

And convention has it that you write Player rather than player.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Well, I'd say that the rule is : one public class per file.
So make your class in separate files. If you insist in using only one file, change two of them so that their are not public.


[My Blog]
All roads lead to JavaRanch
 
 
subject: HF Java 2ed