class grandpaClass {
public grandpaClass() {
System.out.println("1912年 爷爷 出生了");
}
}
class fatherClass extends grandpaClass {
public fatherClass() {
System.out.println("1956年 爸爸 出生了");
}
}
class grandmaMotherClass {
public grandmaMotherClass() {
System.out.println("奶奶的妈妈 是 1890年出生的");
}
}
class gandmaClass {
static int year = 0;
static grandmaMotherClass nnmm = new grandmaMotherClass();
public gandmaClass() {
year = 1911;
System.out.println(year + "年 奶奶 出生了");
}
public gandmaClass(int count) {
year += count;
System.out.println(year + "年 奶奶的妹妹 出生了");
}
}
class motherClass {
public motherClass() {
System.out.println("1957年 妈妈 出生了");
}
}
public class javaclass extends fatherClass {
motherClass b = new motherClass();
static gandmaClass b1 = new gandmaClass();
static gandmaClass b2 = new gandmaClass(2);
public javaclass() {
System.out.println("1981年 我 出生了");
}
public static void main(String[] args) {
System.out.println("mainfunction is called");
javaclass my = new javaclass();
}
}
程序执行结果:
奶奶的妈妈 是 1890年出生的
1911年 奶奶 出生了
1913年 奶奶的妹妹 出生了
mainfunction is called
1912年 爷爷 出生了
1956年 爸爸 出生了
1957年 妈妈 出生了
1981年 我 出生了