package com.itheima;
/**
* 9、
* 有这样三个类,Person,Student.GoodStudent。其中Student继承了Person,GoodStudent继承了Student,
* 三个类中只有默认的构造函数,用什么样的方法证明在创建Student类的对象的时候是否调用了Person的构造函数,
* 在创建GoodStudent类的对象的时候是否调用了Student构造函数?如果在创建Student对象的时候没有调用Person的构造函数
* ,那么采用什么样的手段可以调用父类的构造函数?
*
* @author 281167413@qq.com
*/
public class Test9 {
public static void main(String[] args) {
Student s1 = new Student();
System.out.println("-------------------------------");
Student s2 = new Student();
System.out.println("-------------------------------");
GoodStudent g1 = new GoodStudent();
System.out.println("-------------------------------");
}
}
class Person {
Person() {
System.out.println("I'm Person!");
}
Person(String arg) {
System.out.println(arg);
}
Person(String arg1, String arg2) {
System.out.println(arg1 + arg2);
}
}
class Student extends Person {
Student() {
super("have arg!"); //
System.out.println("I'm Student!");
}
Student(String arg) {
super("have arg!", "in Person");
System.out.println(arg);
}
}
class GoodStudent extends Student {
GoodStudent() {
super("from GoodStudent!");
System.out.println("I'm GoodStudent!");
}
}
have arg! I'm Student! ------------------------------- have arg! I'm Student! ------------------------------- have arg!in Person from GoodStudent! I'm GoodStudent! -------------------------------
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有