• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt ->Accessing from default package

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks joyce and siva for your valuable comments

with regards,

logamanickaraja
SCJP 1.4,preparing for SCWCD
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic