- abstract class YuanGong
- {
- private String name;
- private int age;
- private double pay;
- public abstract void work();
- public void speak()
- {
- System.out.printf("My name is %s,I'm %d",name,age);
- }
- YuanGong(String name,int age)
- {
- this.name = name;
- this.age = age;
- }
- }
- class GuYuan extends YuanGong
- { //声明调用父类的有参构造方法
- GuYuan(String name, int age) {
- super(name, age);
- // TODO Auto-generated constructor stub
- }
- public void work()
- {
- System.out.println("I'm working hard!");
- }
- }
- public class AbstractDemo
- {
- public static void main(String[] args)
- {
- GuYuan yuan = new GuYuan("zhang san",18);
- yuan.speak();
- yuan.work();
- }
- }
复制代码 |