This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes nested Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "nested Packages" Watch "nested Packages" New topic
Author

nested Packages

eshuVenkatRamani
Greenhorn

Joined: Nov 20, 2000
Posts: 7
hi friends,
file:=Test1.java
package testPack;//this is the outer package
public class Test1
{
public Test1()
{
System.out.println("I am the first class constructor in the parent package");
}
}
//the below file I saved under the above package directory and compiled
file:=Test2.java
package testPack1;//this is the inner package
public class Test2
{
public Test2()
{
System.out.println("I am the first class constructor in the next package");
}
}
//both the packages got created and the below file compiled with the classpath specified.
file:=NestPack.java
import testPack.*;
import testPack.testPack1.*;
public class NestPack
{
public static void main(String args[])
{
testPack.Test1 t1=new testPack.Test1();
testPack1.Test2 t2=new testPack1.Test2();
}
}

when executing the above file it displays the contents of first class ,but the Test2 class there is an error
NoClassDefinedFoundError Exception
Please help me out.
------------------
believe in the best


believe in the best
Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
I have the following setup :
In G:\testPack directory :
I have Test1.java compiles to Test1.class (compiles fine). Classpath set to g:\
In g:\testPack\testPack1
I have Test2.java compiles to Test2.class (compiles fine).
In g:\testPack
I have NestPack.java compiles to NestPack.class (compiles fine). As there is not package statement in this file, can be placed here.
HTH
Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
Also prints :
I am the first class constructor in the parent package
I am the first class constructor in the next package
eshuVenkatRamani
Greenhorn

Joined: Nov 20, 2000
Posts: 7
Originally posted by Bharatesh H Kakamari:
Also prints :
I am the first class constructor in the parent package
I am the first class constructor in the next package

thankyou for the answer.
i am saving test1.class in c:\testPack directory.
i am saving test2.class in c:\testPack\testPack1 directory.
i am saving NestPack.java in c: directory
when I am executing It displays only the parent package class constructor and gives error for inner package class constructor.
Just try this and reply me soon
thankyou
eshu
------------------
believe in the best
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nested Packages