• Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding packages in java  RSS feed

 
dineshiop kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have two class

class possiblepath{
}

package possiblepath ;
class b {
}

i want to invoke class a in class b can anybody help me

could anybody say me about the setting that must be done
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dineshiop kumar wrote:

class possiblepath{
}

package possiblepath ;
class b {
}

i want to invoke class a in class b can anybody help me


Where is the class "a" ?
 
dineshiop kumar
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry i am reediting it


class a
{
}

package a;
class b
{
}


now i get a error class not found coud anybody help me

some of my friend said i should set the class path
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dineshiop kumar wrote:
now i get a error class not found coud anybody help me

Please Tell the Details, Which code you are trying ?

And If you're creating instance of class "a" in class "b", then class "b" should be aware of Where to finds the class "a", so while compiling set the classptah using -cp flag.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get no end of confusion if (as you are doing) you mix the default package and named packages. The way you have described your classes, you ought to have a folder called "a" inside the folder containing class"a", and that folder should contain a file called b.class.

It also show how much confusion you can get if you use "a" and "b" as class names and reuse "a" as a package name.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!