Java 中找不到符号错误
我有 3 个类文件,当我编译扩展另一个类的类时,会出现编译错误,例如找不到符号。
public class Animal {
public static void hide() {
System.out.println("Hide Method Of Animal");
}
public void override() {
System.out.println("The Override method of Animal");
}
}
public class Cat extends Animal {
public static void hide() {
System.out.println("Hide Method Of Cat");
}
public void override() {
System.out.println("The Override method of Animal");
}
}
public class TestAnimal {
public static void main(String args[]) {
Cat myCat = new Cat();
Animal myAnimal = (Animal)myCat;
myAnimal.hide();
myAnimal.override();
}
}
我收到此错误:
TestAnimal.java:6: cannot find symbol
symbol : class Cat
location: class com.Test.TestAnimal
Cat myCat = new Cat();
^
对此有任何帮助吗???
I have 3 class file, when i compile the class which extends the other class gives compilation error like symbol not found.
public class Animal {
public static void hide() {
System.out.println("Hide Method Of Animal");
}
public void override() {
System.out.println("The Override method of Animal");
}
}
public class Cat extends Animal {
public static void hide() {
System.out.println("Hide Method Of Cat");
}
public void override() {
System.out.println("The Override method of Animal");
}
}
public class TestAnimal {
public static void main(String args[]) {
Cat myCat = new Cat();
Animal myAnimal = (Animal)myCat;
myAnimal.hide();
myAnimal.override();
}
}
I get this error:
TestAnimal.java:6: cannot find symbol
symbol : class Cat
location: class com.Test.TestAnimal
Cat myCat = new Cat();
^
Any help on this???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,编译后看看每个.java文件是否都有.class文件。如果没有,请确保每个文件都有一个 .class 文件。
运行时,使用 -classpath 参数指向所有 .class 文件所在的目录。
听起来您可以使用一些有关编译和运行 Java 的说明。
http://www.horstmann.com/bigj/help/compiler/tutorial.html
这是勺子喂养的答案:
壳。
Yes, see if there is a .class file for each .java file after you compile. If not, make sure that each one has a .class file.
When you run, use the -classpath argument to point to the directory where all the .class files live.
You sound like you could use some instruction on compiling and running Java.
http://www.horstmann.com/bigj/help/compiler/tutorial.html
Here's the spoon feeding answer:
shell.
你的代码绝对没有问题。这就是我所做的。看看你是否做对了一切:
我使用复制粘贴来获取你的代码,如你所见。请注意,编译后,除了
.java
文件之外,还会出现三个.class
文件。There's absolutely nothing wrong with your code. Here's what I've done. See if you did everything right:
I used copy-paste to get your code, as you can see. Notice that after compiling there are three
.class
files in addition to your.java
files.