Base class does not contain a constructor that takes ' 0 ' argument

Source: Internet
Author: User

Just write a section of the Live Room website in a program, suddenly encountered a mistake, as follows

' Tvllkbll. BaseClass ' does not contain a constructor that takes 0 arguments, according to the holding C # know to analyze the cause of the error

In this case, there are two classes in the business logic, namely

public class BaseClass

{

Public BaseClass (String sql)

{

}

}

public class Baseclasshelp:baseclass

{

Public baseclasshelp (String sql)

{

}

}

Where Baseclasshelp inherits from Pagesclass

The compilation will prompt ' BaseClass ' does not contain a constructor that takes 0 arguments

Why is it?

We know that the class constructor is looking up in layers, until the base class is executed, and then a layer down, and then we look at the constructor baseclasshelp (String sql) in the Baseclasshelp class, and if you do that to the parent class, Instead of specifying which constructor in the parent class to execute, by default the parameterless constructor in the parent class is executed, and if the parent class is modified as follows, the compilation will succeed

public class BaseClass

{

Public BaseClass ()

{

}

Public BaseClass (String sql)

{

}

}

Because he has a parameterless constructor.

Or in a subclass that specifies which constructor to execute in the parent class, the subclass is modified as follows

public class Baseclasshelp:baseclass

{

Public baseclasshelp (String sql) base (SQL)

{

}

}

The subclass constructor then specifies the constructor that executes a parameter in the parent class

Base class does not contain a constructor that takes ' 0 ' argument

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.