jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HF Java 2ed" Watch "HF Java 2ed" New topic

HF Java 2ed

marc valente

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.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
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é

Joined: Nov 24, 2005
Posts: 14688

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
I agree. Here's the link: http://aspose.com/file-tools
subject: HF Java 2ed
It's not a secret anymore!