public class DogTest {
public static void main(String[] args) {
Dog dog = new Dog("Mimi ", "3");
dog.setNickname("Baby");
System.out.println(dog.name + "is" + dog.age + " years old");
System.out.println("It’s nickname is " + dog.getNickname());
Animal animal = new Animal("Tom ", "3");
System.out.println(animal.name + animal.run());
}
}
/**
*
*/
package test;
/**
* @author lilin
*
*/
public class Dog extends Animal {
public Dog(String name, String age) {
super(name, age);
}
private String nickname;
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String run() {
System.out.println("run by four feet");
return null;
}
}
/**
*
*/
package test;
/**
* @author lilin
*
*/
public class Animal {
protected String name;
protected String age;
public Animal(String name, String age) {
this.name = name;
this.age = age;
}
public String run() {
return "can run";
}
}