1. Inheritance
Create Pet Parent class public class pet {private string name;private int age;private int health;private string love;public pet () {// System.out.println ("Parent class no parameter construction method");} 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 ("Parent class has a constructor method");} 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 ("Pet's cry! ");}}
2. polymorphic
This article is from the "Advanced Technology" blog, so be sure to keep this source http://vipnoon.blog.51cto.com/7589908/1792861
Inheritance and polymorphism of Java