• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package problem

 
simran rao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi


i am studying the access modifier chapter from k&b.......i know tht a source file can be put in to a package by including statement in the source code as this....

package mypackage;

but i didnot understand the folder creation for package .......do i need to change my classpath variable.
please help me with a simple eg....such as class one trying to access class two which is in diff pkg.........where will i create the two packages(i mean the absolute path).......
 
Glenn Castro
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a simple example on how to access a class on another class which have different packages:

package example;

public class ClassOne {
//code here
}

-------------------
package test;

import example.ClassOne; //use import to use other classes in diff. package

public class ClassTwo {
ClassOne one = new ClassOne();
//other code here
}
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic