【发布时间】:2017-02-18 08:44:23
【问题描述】:
我在 Windows 10 上使用 Eclipse Neon,试图从 CoreJava 5.2 视频和书籍中运行 ManagerTest.java 文件。
有一个主要类型,但由于某种原因,Eclipse 无法识别它:
我尝试在构建路径中添加继承作为源文件,但没有奏效。我也尝试将 ManagerTest.java 移动到 src 文件夹中,但效果不佳。
每次我右键单击该文件并作为 Java 应用程序运行时,我都会收到错误消息。
提前感谢您的帮助。
代码如下:
package inheritance;
/**
* This program demonstrates inheritance.
* @version 1.21 2004-02-21
* @author Cay Horstmann
*/
public class ManagerTest
{
public static void main(String[] args)
{
// construct a Manager object
Manager boss = new Manager("Carl Cracker", 80000, 1987, 12, 15);
boss.setBonus(5000);
Employee[] staff = new Employee[3];
// fill the staff array with Manager and Employee objects
staff[0] = boss;
staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
staff[2] = new Employee("Tommy Tester", 40000, 1990, 3, 15);
// print out information about all Employee objects
for (Employee e : staff)
System.out.println("name=" + e.getName() + ",salary=" + e.getSalary());
}
}
【问题讨论】:
-
请不要将代码截图放在问题中。复制并粘贴代码文本。