public abstract class Animal { int age; public Animal(int age){ this.age=age; } public abstract void run(); public abstract void clock(); } public class Dog extends Animal{ String color; public Dog(int age,String color){ super(age); this.color=color; } public void run(){ System.out.println("这只"+age+"岁的狗这样跑"); } public void clock(){ System.out.println("这只"+color+"的狗这样叫"); } } public class Test { public static void main(String[] args) { // TODO Auto-generated method stub Dog d1=new Dog(20,"蓝色"); d1.run(); d1.clock(); Dog d2=new Dog(15,"红色"); d2.run(); d2.clock(); } }
本文出自 “技术的秘密” 博客,请务必保留此出处http://liucongcong.blog.51cto.com/11527480/1773827
原文地址:http://liucongcong.blog.51cto.com/11527480/1773827