File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt ->Accessing from default package Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt ->Accessing from default package" Watch "doubt ->Accessing from default package" New topic
Author

doubt ->Accessing from default package

Lok Manick
Ranch Hand

Joined: Jan 24, 2005
Posts: 73
hi guys,

i do like to access a file which is in the default package from a file in the package created.Is it possible to access

default package
first.java
test(the package created)
second.java

i do like to extend second from first.
(second extends first)
or is there any way to import the file in the default package

expecting the answer soon.

with regards,
lokmanick Raja


with regards,
Loks (SCJP, SCWCD, OCEJWSD)
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Lokmanick,

If you're referring to the following scenario, then it's not possible:



This used to be feasible in JDK 1.3, but the feature has been removed since JDK 1.4. See the Bug reports here and here.

Joyce
shivakumar sekaran
Greenhorn

Joined: Apr 15, 2001
Posts: 18
public class Test1{
}

Compile it by saying:

D:\package>javac Test1.java

---------
package test2;

import Test1;

public class Test2 extends Test1{
public static void main(String[] args) {

}
}

Compile this too... by saying:

D:\package>cd test2

D:\package\test2>javac -classpath "D:\package" Test2.java

This will do wonders for you Dude!! Cheerz!
Lok Manick
Ranch Hand

Joined: Jan 24, 2005
Posts: 73
thanks joyce and siva for your valuable comments

with regards,

logamanickaraja
SCJP 1.4,preparing for SCWCD
Praveen Durbha
Greenhorn

Joined: May 16, 2005
Posts: 16
Joyce,

I am not sure why you said it wasn't possible. Here..Check this out.

//class in default package and in file First.java
public class First {
public void first(){
System.out.println("first");
}
}

package cert;
import First; //Possible
//class in package cert and in file Second.java
public class Second {

public static void main(String[] args){

First f = new First();
f.first();
}

}

output: first

Notice you don't have to extend from First since the class is public..meaning it can be accessed outside the package
(default or otherwise)
[ May 20, 2005: Message edited by: Praveen Durbha ]
Praveen Durbha
Greenhorn

Joined: May 16, 2005
Posts: 16
You are probably right Joyce..didn't realize i was running a 1.3.. need to test it on 1.4 though.
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Praveen,

I tried compiling my sample code (see the second post) using JDK 5.0 and 1.4, it just couldn't get thru'. The approach suggested by Shivakumar didn't work too.

Joyce
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt ->Accessing from default package