public abstract class 类名{}
public abstract void 方法名();
package Experience; public abstract class Animal { private String name; private int age; Animal(){ } Animal(String name,int age){ this.name=name; this.age=age; } public abstract void act(); public void setName(String name) { this.name = name; } public String getName() { return name; } public void setAge(int age) { this.age = age; } public int getAge() { return age; } }
package Experience; public class Cat extends Animal{ Cat(){ } Cat(String name,int age){ super(name, age); } @Override public void act(){ System.out.println("猫抓老鼠"); } }
package Experience; public class Test { public static void main(String[] args){ Animal a=new Cat(); a.act(); } }