This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "query" Watch "query" New topic


Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Suppose I have declared 2 classes as public in the same file then compilation does not take place ? Why?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195


Welcome to JavaRanch!

The simplest answer is because that's the rule: there can only be one public top-level class or interface per file.

If you need an explanation: it's just because it makes it easier for the compiler to find the source for a given class if it's in a file with the same name as the class.

[Jess in Action][AskingGoodQuestions]
Kartik Mahadevan
Ranch Hand

Joined: Feb 16, 2005
Posts: 47
Thank U very much
It is sorta covered in the JavaRanch Style Guide.
subject: query
It's not a secret anymore!