We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Simple problem with Java packages

Xavior2K3 asked
Medium Priority
Last Modified: 2010-03-31

I have a class, classA (that is not in any package) that refers to another one of my classes, classB (also not in a package).
My problem is that when i put classA in a package, pack1, the complier says it cannot find the symbol classB. What am i doing wrong?

Watch Question

Top Expert 2006

path to A should be in classpath


Can you give me an example?
Top Expert 2006

Sorry it seems that named package classes cannot access default package classes.
I'll look for a workaround
Public classes can be accessed by any other class.
You probably forgot to make them public.

And if JAVA can't find a class it's because the import statement is incorrect.

Top Expert 2006
The problem is that a named package class can not import a default package class and also classpath in this case wont help

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

1. Import the class:

import classB;

2. It is discouraged to make default package classes.  Just put it in a package.  (And import it!)

Unnamed packages are provided by the Java platform principally for convenience when developing small or temporary applications or when just beginning development.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.