public abstract class Person {
public abstract String getDescription();
public String getName(){return null;}
}
---------------------------------------------------------------------------------
public class Employee extends Person
{
public Employee(String n,double s)
{
name=n; //error
salary=s;
}
public String getName()
{
return name; //error
}
public String getDescription()
{
return String.format("an employee with a salary of $%.2f",salary);
}
private double salary;
private name; //error
}
--------------------------------------------------------------------------------------------
public class Student extends Person
{
public Student(String n,String m)
{
name=n; //error
major=m;
}
public String getName()
{
return name; //error
}
public String getDescription()
{
return "a student majoring in"+major;
}
private String major;
private name; //error
}
----------------------------------------------------------------------------------------------
public class PersonTest {
public static void main(String[] args) {
Person [] people=new Person[2];
people[0]=new Employee("Harry Hacker",50000);
people[1]=new Student("Maria Morris","computer science");
for(Person p:people)
System.out.println(p.getName()+"."+p.getDescription());
}
}
为什么说我name错啊
我想实现多态!
[此贴子已经被作者于2006-11-11 12:41:37编辑过]