在java中,一个父类可以有多个子类,但是子类只能有一个父类。子类通常通过关键字extends来继承父类。
public class Animal {
int a = 3;
AnimalClass() {
System.out.println("父类无参构造函数");
}
AnimalClass(int i) {
System.out.println("有一个形参i");
}
AnimalClass(int i,int j){
System.out.println("有两个形参i,j");
}
}
class DogClass extends AnimalClass {
int a;
int b;
public DogClass() {
System.out.println("123一起上");
}
public class DogClass(int a) {
this a = a;
System.out.println("456一起上");
}
public AnimalClass() {
super.(3,4);
}
public show() {
System.out.println("show 好!");
}
public static void main(String[] args) {
DogClass sc1 = new Dogclass ();
AnimalClass sc2 = new Animalclass ();
AnimalClass sc3 = new Animalclass (3,4);
}
}
这就是一个简单的父类与子类