日期:2014-05-20 浏览次数:20660 次
import java.util.*;
public class Test
{
public static void main(String[] args)
{
Employee[] employee = new Employee[2];
employee[0] = new A("ert", "computer");
employee[1] = new B("rty", 5000);
for(Employee i: employee)
{
System.out.println(i.getName()+","+i.getMajor()+","+i.getSalary());
}
}
}
abstract class Employee
{
private String name;
public Employee(String n)
{
name = n;
}
public String getName()
{
return name;
}
public abstract String getMajor();
public abstract double getSalary();
}
class A extends Employee
{
private String major;
public A(String n, String m)
{
super(n);
major = m;
}
public String getMajor()
{
return major;
}
class B extends Employee
{
private double salary;
public B(String n, double x)
{
super(n);
salary = x;
}
public double getSalary()
{
return salary;
}
}
class A extends Employee
{
private String major;
public A(String n, String m)
{
super(n);
major = m;
}
public String getMajor()
{
return major;
}//这里少个括号
}