• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Package Members

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


package may not contain two members of the same name, or a compile-time error results.
Here are some examples:
Because the package java.awt has a subpackage image, it cannot (and does not) contain a declaration of a class or interface type named image.
If there is a package named mouse and a member type Button in that package (which then might be referred to as mouse.Button), then there cannot be any package with the fully qualified name mouse.Button or mouse.Button.Click.



One class in Java cannot reside under two packages


I try to verify that and i'm not getting what was expected i.e no compile time error at all.
Having a package, a class or a any member type in that package with the same name works fine.
I would appreciate your insights regarding this.
Thx.

 
Shishio San
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
source of the first quote JLS
http://java.sun.com/docs/books/jls/second_edition/
html/packages.doc.html#73659
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Shishio:


package may not contain two members of the same name, or a compile-time error results.


I believe "members" in above statement refer to member classes or interfaces. Therefore, two classes/interfaces with same name are not allowed in with in one package. For example following code will not compile:

The package name and class name could be same.
Hope this helps.
Barkat
[ October 06, 2002: Message edited by: Barkat Mardhani ]
[ October 06, 2002: Message edited by: Barkat Mardhani ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic