Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error

 
Andrei Mircescu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the next code



and the next errors:
1. class game is public,should be declared in a file named game.java
2. class player is public, should be declared in a file named player.java

i use jcreatorle...

i'm trying to learn java from head first java 2.0, as you may assume, i'm a fast learner.
I'm good at C but i only know to work procedural but now i start to understand OO

please tell me what i'm doing wrong because i can't see the problem...
//best regards
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please use more informative thread titles than "Error."

If you call a class public, then the .java file has to have the same name. You need to write player (It should actually be Player) in a file called player.java, and game (or better Game) in the game.java file. Yes, you need two files. Most compilers enforce that requirement.
 
Eric Weinberg
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Andrei,

Take some time to read the exceptions and try and get an idea for what they are saying. Java errors usually pretty helpful.

class game is public,should be declared in a file named game.java

It's saying that because the game class is public, the name of the file needs to be called game.java Here is some more information.
 
Andrei Mircescu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank a lot...i've just did my problem...

thank again for the help, i didn't expect to answer me so soon

a question...if i read all the head first java 2 i am ok for scja ?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrei Mircescu wrote:thank a lot...i've just did my problem...

thank again for the help, i didn't expect to answer me so soon
You're welcome

Andrei Mircescu wrote:a question...if i read all the head first java 2 i am ok for scja ?
Don't know. I shall try moving this thread elsewhere, and see whether you get more answers there.
 
Andrei Mircescu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ritchie
 
Vopli Vidoplyasova
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrei Mircescu wrote:a question...if i read all the head first java 2 i am ok for scja ?

No, you're not. Head First Java is awesome, but there's a lot of things you need to know in order to pass the exam not covered in the book. I would recommend both Cameron's books plus practice exam at Sun's website.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic