【发布时间】:2012-08-11 14:29:59
【问题描述】:
代码如下:
public class EmployeeTest
{
public static void main(String args[]){
//System.out.println("hello world");
Employee aEmployee = new Employee("David",1000);
System.out.println(aEmployee.getName() + aEmployee.getSalary());
}
}
class Employee // **why can't I put a "public" here**
{
// Constructor
public Employee(String name, double salary)
{
this.name = name;
this.salary = salary;
}
// Methods
public String getName()
{
return this.name;
}
public double getSalary()
{
return this.salary;
}
// instance field
private String name;
private double salary;
}
我的问题是:在第二类定义的第一行,为什么我不能放一个“public”来定义它? 当使用它定义一个类时,“public”的确切含义是什么?
【问题讨论】:
-
如果它在一个名为 Employee.java 的文件中,您可以在那里公开它