Error:implicit Super Constructor people () is undefined for default constructor. Must define an explicit constructor

Source: Internet
Author: User

When a subclass inherits the parent class, if the parent class does not have a constructor that defines the parameter, the subclass can inherit the default constructor of the parent class

When a constructed method with parameters is defined in the parent class, the subclass must explicitly call the parent class's constructor method

If, at this point, the subclass also wants to invoke the default constructor method of the parent class, the default constructor must be explicitly declared in the parent class

1  PackageCom.gaohui;2 3  Public classTest {4      Public Static voidmain (String [] args) {5Man mans =NewMan ("Tom"));6 man.eat ();7Man.eat ("Tom");8 Man . Exercise ();9Woman Woman =NewWoman ();Ten          One     } A      - } -  the classpeople{ -     Private intAge ; -     PrivateString name; -     PrivateString sex; +      -      Publicpeople () { +         //if the parent class does not declare a default constructor method, the subclass must explicitly call the constructor of the parent class definition when it inherits A     } at      -      PublicPeople (intAge , String name) { -System.out.println ("Construction method one executed!") "); -     } -      -      Public voideat () { inSYSTEM.OUT.PRINTLN ("People need to eat!"); -     } to      +      Public voidEat (String name) { -System.out.println (name+ "needs to eat!"); the     } *      $     Panax Notoginseng } -  the classMansextendspeople{ +      PublicMans (intAge, String name) {//because the parent class's constructor method is a parameter, you must explicitly call the parent class's method A         Super(age,name); the     } +      -      Public voidExercise () { $System.out.println ("I Love doing exercise!"); $     } - } -  the  - classWomanextendspeople{Wuyi      the}

Error:implicit Super Constructor people () is undefined for default constructor. Must define an explicit constructor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.