开发者

how to import user defined packages in java program? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help cl开发者_如何学Pythonarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.
some.java
import A.A1.*;

Directory structure
  A
  |_A2
  |  |_some.java
  |_A1
     |_someother files and java files

but import statement didn't work. What is the reason?


I hope A is not your current directory.

Perhaps you already know that packages work with directory heirarchies.

<curr-dir>
 |-A
 | |-A1
 | | |- Class1.class
 | | `- Class2.class
 | `-A2
 |   |-Class3.class
 |   `-Class4.class
 `-<other dirs>

Now if <curr-dir> is in your classpath then import A.A1.* will import Class1 and Class2.

Hope that is detailed enough :)


Any class in a given package must have a package statement, and must be declared public (in most cases) to be read outside the package:

package A.A1;
public class ClassName{}


package A.A1;

import A.A2.*;

public class ex2{}


Dude *(star operator) does not work for user created packages! you need to import each class individually..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜