This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Named Vs Unnamed Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Named Vs Unnamed Packages" Watch "Named Vs Unnamed Packages" New topic
Author

Named Vs Unnamed Packages

Sudhanshu Mishra
Ranch Hand

Joined: May 28, 2011
Posts: 207

Hi all,
I have a little doubt regarding two codes:

file Bclasse.java
package BBB;
class Bclasse extends Aclasse
{
public static void main(String...a)
{
}
}

File Aclasse.java
public class Aclasse
{
public static void main(String...a)
{
System.out.println("printed in class A");
}
}


Now as you can see that the two codes are in separate files,why is Bclasse unable to access Aclasse even if Aclasse is public.Is it because Aclasse is in unnamed package and Bclasse is in a named package?How does that makes a difference?


Thanks....
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Though the class is public, since it's in different package, you have to import it. But for importing the class, you have to specify the fully qualified class name with the package name. So you have no chance of importing classes in default package and using it in a class that belongs to a named package.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Named Vs Unnamed Packages
 
Similar Threads
How to deploy and run a java executable with package?
My first interface
pathing issue
Test Drive
Enable assertions in current package.