//父类
class Animal{
private String name;
private int age;
Animal(String name, int age) {//创建父类构造器
super();
this.name = name;
this.age = age;
}
public String setName(){//传递参数
return name;
}
public int setAge(){//传递参数
return age;
}
}
//子类
class Fish extends Animal{
public String color;
Fish(String name, int age,String color) {//创建父类构造器
super(name, age);//调用父类的构造器
this.color=color;
}
}
//测试类
public class myanimal {
public static void main(String[] args) {
Fish f=new Fish("尼莫",18,"橘黄色");
System.out.println(f.setName()+"
"+f.setAge()+"
"+f.color);
}
}