wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes is subpackage considered as same package? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "is subpackage considered as same package?" Watch "is subpackage considered as same package?" New topic

is subpackage considered as same package?

adam Lui
Ranch Hand

Joined: Sep 03, 2007
Posts: 186
consider the following code:

so here we have a subclass access a superclass instance, which are both in the "root" package world,
if i get rid of public at line 1, the compiler complaints.
is it because of subpackage is not considered as same package, or something else is wrong in the code?

just one more thing,
if i use
import world.moon;
in the world class,
why does it not work?
[ November 05, 2007: Message edited by: adam lui ]

boolean b = true;<br />System.out.println ("I believe in Java.<br />Java will make my dream come " + b);
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
Hi Adam,

There's no such thing as a subpackage in Java. For all intents and purposes, "world" and "world.moon" are completely different packages. This is a bit non-intuitive because the .class files are stored hierarchically in the file system... but they don't in fact share a "subpackage" relationship in Java.

SCJP 5.0
I agree. Here's the link: http://aspose.com/file-tools
subject: is subpackage considered as same package?
Similar Threads
extension mechanism and javac
accessing the super class variable
Two Constructers
Errors when compiling these classes...