【发布时间】:2019-09-11 16:13:54
【问题描述】:
我有两节课。当我将类 TapeDeckTestDrive 首先放在文本编辑器上时,它运行良好。当我把TestDrive类放在第一位时,它给出了找不到主类的错误。这是为什么呢?
class TapeDeck {
boolean canRecord = false;
void playTape(){
System.out.println("tape playing");
}
void recordTape(){
System.out.println("tape recording");
}
}
class TapeDeckcTestDrive{
public static void main(String[] args){
TapeDeck t = new TapeDeck();
t.canRecord = true;
t.playTape();
if (t.canRecord == true) {
t.recordTape();
}
}
}
此格式错误
VS
以下工作正常:
class TapeDeckcTestDrive{
public static void main(String[] args){
TapeDeck t = new TapeDeck();
t.canRecord = true;
t.playTape();
if (t.canRecord == true) {
t.recordTape();
}
}
}
class TapeDeck {
boolean canRecord = false;
void playTape(){
System.out.println("tape playing");
}
void recordTape(){
System.out.println("tape recording");
}
}
【问题讨论】:
-
你的java类(文件)名是什么?
-
解决这个问题的简单方法,也是最好的方法是每个文件有一个类。
-
@Abdul Hussain 请告诉文件名
-
它运行良好,它给出了错误:什么是“它”。你如何执行你的应用程序?
-
这不是执行课程的最佳方式。首先你用 javac 编译你的代码。然后使用 java 并传递包含 main 方法的类的完全限定名称。