class Animal
{
public Animal(){
System.out.println("Animal 的构造函数...");
}
public Animal(String x){
System.out.println("Animal 带一个参数的构造函数"+ x);
}
public void eat(){
System.out.println("Animal eat....");
}
}
public class Cat extends Animal{
public Cat(){
System.out.println("Cat 的构造函数...");
}
public Cat(String x){
System.out.println("Cat带一个参数的构造函数..."+ x);
}
public void eat(){
System.out.println("Cat eat...");
}
public static void main(String[] args) {
Animal one = new Animal();
one.eat();
/* Animal 的构造函数...
Animal eat....*/
Animal five = new Animal("haha");
//Animal 带一个参数的构造函数haha
Animal two = new Cat(); //父类声明,子类实现,行为表现是子类,子类构造函数若带参数,会调用父类无参数的构造方法
two.eat();
/*Animal 的构造函数...
Cat 的构造函数...
Cat eat...*/
Animal four =new Cat("hehe");
four.eat();
/*Animal 的构造函数...
Cat带一个参数的构造函数...hehe
Cat eat...*/
Cat three = new Cat();
three.eat();
/*Animal 的构造函数...
Cat 的构造函数...
Cat eat...*/
Cat hehe = new Cat("memeda");
/*Animal 的构造函数...
Cat带一个参数的构造函数...memeda*/
}
}
class baba
{
public static void show()
{
System.out.println("我是爸爸类的静态方法...");
}
public void show(int x)
{
System.out.println("爸爸带一个参数"+x);
}
}
public class erzi extends baba{
public static void show()
{
System.out.println("我是儿子的重写静态方法...");
}
public void show(int x)
{
System.out.println("儿子带一个参数"+x);
}
public static void main(String[] args) {
baba.show();
erzi.show();
System.out.println("--------------------------------");
baba one = new baba();
one.show();
one.show(5);
System.out.println("--------------------------------");
baba two = new erzi();
two.show();
two.show(5);
}
}
/*
我是爸爸类的静态方法...
我是儿子的重写静态方法...
--------------------------------
我是爸爸类的静态方法...
爸爸带一个参数5
--------------------------------
我是爸爸类的静态方法...
儿子带一个参数5
*/