java抽象类

抽象类

在这里插入图片描述

public abstract class a01 {
    public abstract void test();
    public abstract void move();
    public static void main(String[] args) {
        Dog d=new Dog();
        Fish f=new Fish();
        f.move();
        d.move();
    }
}
class Dog extends a01{//抽象类必须要继承才能被使用;抽象类中的抽象方法均需要被重写
    public void test() {
    }
    public void move() {
        System.out.println("狗儿跑,狗儿爬");
    }
}
class Fish extends a01{
    public void test() {
    }
    public void move() {
        System.out.println("小甲鱼游啊游");
    }
}
abstract class Bird extends a01{
    public void test() {
    }
    public abstract void move();//若类中有一个抽象方法那这个类必然为抽象类
}

在这里插入图片描述
在这里插入图片描述

例2.
在这里插入图片描述

package a;

public abstract class a01 {
    public a01(){}
    int id;
    String name;
    double salary;
    public abstract void work();
}
class CommontEmployee extends a01{
    public void setCommontEmployeeInfo(int id,String name,double salary){
        super.name=name;
        super.id=id;
        super.salary=salary;
    }
    public void getCommontEmployeeInfo(){
        System.out.println(super.name);
        System.out.println(super.id);
        System.out.println(super.salary);
    }
    public void work(){
        System.out.println("这是一个普通员工");
    }
}
class Manager extends a01{
    double jj;
    public void work(){
        System.out.println("这是一个经理");
    }
    public void setManagerInfo(int id,String name,double salary,double jj){
        super.name=name;
        super.id=id;
        super.salary=salary;
        this.jj=jj;
    }
    public void getManagerEmployeeInfo(){
        System.out.println(super.name);
        System.out.println(super.id);
        System.out.println(super.salary);
        System.out.println(this.jj);
    }
}





package a;

public class a02 {
    public static void main(String[] args) {
        CommontEmployee ce=new CommontEmployee();
        ce.work();
        ce.setCommontEmployeeInfo(423,"kiana",22333);
        ce.getCommontEmployeeInfo();
    }
}


运行结果:
这是一个普通员工
kiana
423
22333.0

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值