抽象类
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