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 package name and class name 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 "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
internet detective
Marshal

Joined: May 26, 2003
Posts: 26184
    
  66

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: package name and class name
 
Similar Threads
package & classpath I am lost !
Q of inner class in different package
Accessing a class of default package
how to make two classes in a packahe where one class extends the other
Reg. Packages