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