Error: Implicit super constructor People () is undefined for default constructor. Must define an explicit constructor, explicitconstructor
When a subclass inherits the parent class, if the parent class does not define a constructor with parameters, the subclass can inherit the default constructor of the parent class.
When a constructor with parameters is defined in the parent class, the subclass must explicitly call the constructor of the parent class.
If the subclass also wants to call the default constructor of the parent class, it must explicitly declare the default constructor in the parent class.
1 package com. gaohui; 2 3 public class Test {4 public static void main (String [] args) {5 Man = new man (24, "Tom"); 6 Man. eat (); 7 man. eat ("Tom"); 8 man. exercise (); 9 Woman woman = new Woman (); 10 11} 12 13} 14 15 class People {16 private int age; 17 private String name; 18 private String sex; 19 20 public People () {21 // if the parent class does not declare the default constructor, the constructor defined by the parent class must be explicitly called during subclass inheritance 22} 23 24 public People (int age, String name) {25 System. out. println ("constructor 1 is executed! "); 26} 27 28 public void eat () {29 System. out. println (" People need to eat! "); 30} 31 32 public void eat (String name) {33 System. out. println (name +" needs to eat! "); 34} 35 36 37} 38 39 class Man extends People {40 public Man (int age, String name) {// because the constructor of the parent class has parameters, must explicitly call the parent class Method 41 super (age, name); 42} 43 44 public void Exercise () {45 System. out. println ("I love doing exercise! "); 46} 47} 48 49 50 class Woman extends People {51 52}