最近开始学习Java考试.
学习包时,试过这个并收到错误信息.我做的是,
//Creating class A (Within package the package: com.test.helpers)
package com.test.helpers;
public class A {
public void sayHello(){
System.out.println("Hello World");
}
}
Run Code Online (Sandbox Code Playgroud)
//And then the class App utilizing the class A
import com.test.helpers.*;
public class App{
public static void main(String args[]){
A a = new A();
a.sayHello();
}
}
Run Code Online (Sandbox Code Playgroud)
我将这两个文件放在名为"JavaTest"的目录中(在Windows 7上),并首先使用命令"javac -d.A.java"编译A.java.
然后,在尝试编译App.java时,我收到以下错误消息:
App.java:5: error: cannot access A
A a = new A();
^
bad source file: .\A.java
file does not contain class A
Please remove or make sure …Run Code Online (Sandbox Code Playgroud)