我是 Java 编程语言的新手。我做了一个包名包。其中包含两个java类A.java和B.java。我正在使用 jdk1.5 和 tomcat。我想创建一个 A 类型的对象并将其放在 B.java 中。以下是我尝试执行此操作但收到两条错误消息的方法。
包装包;
爪哇
public class A {
private String str;
public A(){} //constructor method
public void setName(String str){
this.str = str;
}
public String getName(){
return str;
}
}
B.java
public class B {
private String temp;
public B(){} //constructor method
public String getTemp(){
A a = new A(); //creating an object of A type
temp = a.getName(); //assigning the value of getName method to temp variable
return temp; // returning temp variable
}
}
jdk1.5、tomcat和包包在下面目录
D:\java>
以下是我编译 A.java 和 B.java 的步骤
编译A.java
D:\>cd java
D:\Java>cd pack
D:\Java\pack>set path=D:\java\jdk1.5\bin (**setting up path of jdk1.5**)
D:\Java\pack>javac A.java (**Compiling A.java. Compiled it successfully**)
编译B.java
D:\Java\pack>javac A.java (**Compiling B.java. Unable to compile**)
**(Error Message is below)**
D:\Java\pack>javac B.java
B.java:9: cannot find symbol
symbol : class A
location: class pack.B
A a = new A(); //creating an object of A type
^
B.java:9: cannot find symbol
symbol : class A
location: class pack.B
A a = new A(); //creating an object of A type
^
2 errors