1. package student;
    2. public class Exercise01 {
    3. public static void main(String[] args) {
    4. B b = new B();//a , b name, b
    5. }
    6. }
    7. class A {
    8. A() {
    9. System.out.println("a");
    10. }
    11. A(String name) {
    12. System.out.println("a name");
    13. }
    14. }
    15. class B extends A {
    16. B() {//有this()就不会调用有super()
    17. this("abc");
    18. System.out.println("b");
    19. }
    20. B(String name) {
    21. //默认有 super();
    22. System.out.println("b name");
    23. }
    24. }

    image.png

    1. package student;
    2. public class Exercise02 {
    3. public static void main(String[] args) {
    4. C c = new C();
    5. }
    6. }
    7. class A {//A类
    8. public A() {
    9. System.out.println("我是A类");
    10. }
    11. }
    12. class B extends A { //B类,继承A类 //main方法中: C c =new C(); 输出么内容? 3min
    13. public B() {
    14. System.out.println("我是B类的无参构造");
    15. }
    16. public B(String name) {//默认调用super()
    17. System.out.println(name + ":我是B类的有参构造");
    18. }
    19. }
    20. class C extends B { //C类,继承 B类
    21. public C() {
    22. this("hello");
    23. System.out.println("我是c类的无参构造");
    24. }
    25. public C(String name) {
    26. super("wty");
    27. System.out.println("我是c类的有参构造");
    28. }
    29. }

    image.png