This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes compiler telling me to make a file for a public class Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "compiler telling me to make a file for a public class" Watch "compiler telling me to make a file for a public class" New topic
Author

compiler telling me to make a file for a public class

derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Hi, any help greatly appreciated. The compiler is telling me that since two of my classes are "public", that I need to make separate files for them, which I know should not be the case right? So I pasted the code below so you can see it. and after that I posted the error. please. thank you gurus! Derek






On a side note! I would like to share a great trick with fellow newbie programmers, and when I say newbie, I mean first born. LOL. Ok, you select your compiler errors or type them, then google them in quotes, and search for the solution. If that doesn't work, try the forum, that's what I did.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

derek smythe wrote:The compiler is telling me that since two of my classes are "public", that I need to make separate files for them, which I know should not be the case right?


Nope. The compiler is right. A java file can only have one public top-level class, and that class has the same base name as the file.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
derek smythe
Ranch Hand

Joined: Apr 18, 2011
Posts: 63
Nevermind everything works now, I got it to run. Thanks so much for the help! This is like giving birth, LOL, if a man can give birth I just did.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32694
    
    4
derek smythe wrote:. . . if a man can give birth I just did.
Series II episode 6 ("Parallel Universe")
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: compiler telling me to make a file for a public class
 
Similar Threads
Incompatible magic value 188741100
Question about classes and running source code.
Errors when compiling these classes...
Major problem with GuessGame code, ch02 of "Head First Java, 2nd edition, covers Java 5.0"
GuessGame.java:2: cannot resolve symbol