Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

nested Packages

 
eshuVenkatRamani
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also prints :
I am the first class constructor in the parent package
I am the first class constructor in the next package
 
eshuVenkatRamani
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic