aspose file tools*
The moose likes Beginning Java and the fly likes package name and class name 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 "package name and class name" Watch "package name and class name" New topic
Author

package name and class name

lyko saha
Greenhorn

Joined: Aug 21, 2004
Posts: 5
In Chapter 6: Objects and Classes (Sun Website) By Simon Roberts, Philip Heller, and Michael Ernest
The authors mentioned that:
�It is illegal for a package and a class to have the same name, so there can be no ambiguity.�

However, when I tried to compile the following code, it was successful.
Why is it so? I mean, how can I prove it?

package P1;
class P1 {}

This is saved as P1.java in a directory P1 (which is again in a directory specified in my classpath)
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30752
    
156

Lyko,
Welcome to JavaRanch! I think that means that you can't have a package and class with the same name at the same level.

For example:
1) package jeanne.Test;
2) package jeanne;
class Test() { ... }

This would be illegal because jeanne.Test would be ambiguous.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Note that the fully qualified name of the class you posted is P1.P1, while the name of the package is simply P1. So, P1.P1 != P1


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package name and class name