1、继承
//创建Pet父类 public class Pet { private String name; private int age; private int health; private String love; public Pet(){ //System.out.println("父类无参构造方法"); } public Pet(String name,int age,int health,String love){ this.name = name; this.age = age; this.health = health; this.love = love; //System.out.println("父类有参构造方法"); } 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 int getHealth() { return health; } public void setHealth(int health) { this.health = health; } public String getLove() { return love; } public void setLove(String love) { this.love = love; } public void print(){ System.out.println(name+"\t"+age+"\t"+health+"\t"+love); } public void shout(){ System.out.println("宠物的叫声!"); } }
2、多态
本文出自 “技术进阶” 博客,请务必保留此出处http://vipnoon.blog.51cto.com/7589908/1792861
原文:http://vipnoon.blog.51cto.com/7589908/1792861