Error: Implicit super constructor XX () is undefined for default constructor.

Source: Internet
Author: User
Error: Implicit super constructor XX () is undefined for default constructor. Must define an explicit constructor
Because your parent class has defined a constructor with a parameter and there is no default parameterless constructor in the parent class , the compiler will not invoke the default constructor for you at this time, and when the subclass inherits, you must explicitly call the constructor of the parent class in its own constructor to  Make sure that the parent class is instantiated before initialization , and if you have parameterless constructors in your parent class , the subclass will not force a call, that is, the one you write can pass, and the compiler will help you invoke the constructor of the parent class by default. According to the original idea, must be the following:
Class Person { 
	protected String name; 
	protected int age; 
	You have defined an automatic constructor, at which point the compiler will not create a default constructor for you 
	(String name,int age) { 
		this.name=name; 
		this.age=age; 
	} 
	public void print () { 
		System.out.println ("Name:" +name+ "/nage:" +age); 
	} 
/* Because the constructor of the parent class is a parameter, the compilation does not automatically call the default constructor for you, at which point the subclass must explicitly call the constructor of the parent class in its own constructor/class
Student extends person {public 
	Student () {      //Subclass Constructor 
	//super ();   No, because your parent class has no parameterless constructor 
	
	super ("a", 1); 
      Displays the constructor that invokes the parent class, and must be the first line of call 
	} 
	class Test {public 
		static void Main (String args[] 
		) 


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.