package bbs;
class Animal
{
String name ="ani";
int age = 3;
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;
}
Animal()
{}
Animal(int age )
{
this();
this.age = age;
}
Animal(String name,int age)
{
this(age);
this.name = name;
}
public void show()
{
System.out.println(this.getName()+this.getAge()+"--------------");
}
}
class Dog extends Animal
{
String name ="dog";
int age = 6;
Dog()
{
super();
}
Dog(int age)
{
super(age);
}
Dog(String name,int age)
{
super(name,age);
}
public void show()
{
System.out.println(this.getName()+this.getAge()+"+++++++++++++++");
}
}
public class SuperDemo {
public static void main(String[] args) {
Animal a1 = new Animal();
Animal a2 = new Animal(23);
Animal a3 = new Animal("jaja",25);
a1.show();
a2.show();
a3.show();
Dog d1 = new Dog();
Dog d2 = new Dog(1);
Dog d3 = new Dog("wangcai",5);
d1.show();
d2.show();
d3.show();
}
}
|