本帖最后由 王亚飞 于 2013-3-18 12:47 编辑
- abstract class yg
- {
- private String name;
- private String id;
- private double pay;
- yg(String name,String id,double pay)
- {
- this.name = name;
- this.id = id;
- this.pay = pay;
- }
- public abstract void work() ;
- }
- class mg extends yg
- {
- private double jiangjin;
- mg(String name,String id,double pay,double jiangjin)
- {
- super(name,id,pay);
- this.jiangjin = jiangjin;
- }
- public void work()
- {System.out.println("mg work");
- }
- }
- class por extends yg
- {
- por(String name,String id,double pay)
- {
- super(name,id,pay);
- }
- public void work()
- {
- System.out.println("por work");
- }
- }
- //看到抽象类的练习视频,看完了自己做了个,发现有错误,父类写了抽象方法,类名报错,和视频对了对也没发现自己哪写的和视频不一样,后来发现,父类定义了抽象方法,父类的类名中也得加抽象关键字,但是看视频没写,又找了找笔记发现确实是抽象方法必须放在抽象类中。心里还有点嘀咕,视频里父类不是抽象类,里面有抽象方法,这样是不对的吧。必须得把这个类写成抽象类吧?
复制代码 |