This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Importing Classes in default package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Importing Classes in default package" Watch "Importing Classes in default package" New topic

Importing Classes in default package

swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
Is there a way to import classes in default package (having no package statement at all)?

Have a file

public class Test {

Have another file Test2 in package com

package com;
public class Test2 {
public static void main(String[] args) {
//Test test = new Test();

Is there any way of importing
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
No you cannot import them unless they are in a package.

As long as the directory containing the .class file is in the CLASSPATH, you should be able to use the type.
I agree. Here's the link:
subject: Importing Classes in default package
It's not a secret anymore!