abstract class Employee
{
private String name;
private String id;
private double pay;
Employee(String name,String id,double pay)
{
this.name = name;
this.id = id;
this.pay = pay;
}
public abstract void work();
}
class pro extends Employee
{
pro(String name,String id,double pay)
{
super(name,id,pay);
}
public void work()
{
System.out.println("pro work");
}
}
class EmployeeDemo
{
public static void main(String[] args)
{
//new pro().work();//因为你pro对象中没有无参的构造函数,所以创建匿名对象时不能使用无参数的匿名对象进行创建,
new pro("zhangsan","m1009",100.5).work();//正确创建和调用方式,或者在pro类中添加空参的构造函数
}
}
|