【发布时间】:2014-01-14 05:37:09
【问题描述】:
我目前正在参加一个在线 Java 课程,我的导师让我相信所有 Java 课程都必须有一个 main 方法
即。
public class
{
public static void main(String[] args)
}
但是,我们刚刚到达了一个关于交叉引用其他文件中的类的单元,但情况并非如此。
例如
public class Pie
{
// declare variables to be called in separate file
String type;
int diameter;
float radius;
}
然后可以以如下方式引用饼图:
Pie newPie = new Pie();
System.out.println("What type of pie will you be eating today?");
newPie.type = in.readLine();
System.out.println("Ah. " + newPie.type + ". Excellent choice.\n");
这很好用。然而,为什么这个功能正确地隐藏了我的解释。谁能解释一下?
【问题讨论】:
-
所有 Java 应用程序必须包含至少一个带有 main 方法的类;但可能包含其他没有主要方法的类。
-
要么你误解了你的导师,要么他不知道他在说什么。我的钱是前者。