-
Packages
Hi!
I have a little problem.
Let's say I have these scripts:
Code:
package blah;
public class InPack {
public boolean pack() {
System.out.println("BLAH");
return true;
}
}
Code:
import blah.*;
public class Decrypter {
public static void main(String[] args) {
boolean pck = pack();
}
}
First one is in package "blah" and second is in default package.
I can't acess boolean pack() through imports but I can acess it in this way:
Code:
blah.InPack x = new blah.InPack();
boolean pck = x.pack();
How can I acess pack() trough imports? What am I doing wrong?
Thanks.
-
Hi,
It is not possible to access the method without creating an object.
Go thru this link
Lesson: Packages (The Java™ Tutorials > Learning the Java Language)
and also see the modification below for ur code:
Code:
import blah.*;
public class Decrypter {
public static void main(String[] args) {
//Create an object for InPack class
InPack obj = new InPack();
//Use the above created object to access the method
boolean pck = obj.pack();
}
}
-
Thanks..really helped me!