-
抽象方法
-
抽象类和抽象方法的定义格式
-
代码演示
-
-
抽象类和抽象方法的注意事项
-
抽象类和抽象方法的意义
为了统一性,以后开发软件等多项的时候不是我一个人开发,我们需要统一性来节约时间
-
练习
动物类
public abstract class Animal { private String name; private int age; public Animal() { } public Animal(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public abstract void eat(); public void heshui(){ System.out.println("喝水"); } }
羊类
public class yang extends Animal{ public yang() { } public yang(String name, int age) { super(name, age); } @Override public void eat() { System.out.println(getName()+"在吃艹"); } }
青蛙类
public class qw extends Animal{ public qw() { } public qw(String name, int age) { super(name, age); } @Override public void eat() { System.out.println(getName()+"在吃虫子"); } }
狗类
public class dog extends Animal{ public dog() { } public dog(String name, int age) { super(name, age); } @Override public void eat() { System.out.println(getName()+"在吃骨头"); } }
测试类
public class test { public static void main(String[] args) { qw q = new qw("金蟾",100); q.eat(); q.heshui(); dog d = new dog("哮天犬",10); d.eat(); d.heshui(); yang y = new yang("小羊肖恩",1); y.eat(); y.heshui(); } }
-
-
总结
-