When using Windows cmd (and Notepad++) i am able to call methods from other classes if they are all in default package
However, I am unable to do so if i define classes in any package other than default package.
Am facing this problem in NetBeans and Eclipse as well
Any help is appreciated
If you are defining class in package-A, it must be public , if you want to use it in package-B
package package-A;
public class A{
public void hello();
}
package package-B;
public class B{
public static void main(String[] args){
A a = new A();
a.hello();
}
}
Because by-default access-modifier is default , so it will be accessable in that particular package only.
To learn more about access modifiers: Click Here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.