1
If a class defines a constructor with parameters only, does C# still provide a default parameterless constructor?
DiscussEasy
Loading subject content…
Loading practice questions…
If a class defines a constructor with parameters only, does C# still provide a default parameterless constructor?
What is the output of the following program?
Console.WriteLine(new P().V);
class P {
public int V;
public P() : this(7) { }
public P(int v) { V = v; }
}What is the output of the following program?
var r = new Rect(4);
Console.WriteLine(r.Area);
class Rect
{
public int W, H;
public Rect(int s) : this(s, s) { }
public Rect(int w, int h) { W = w; H = h; }
public int Area => W * H;
}What is the output of the following program?
var a = new A();
class A
{
public A() { Console.Write("ctor"); }
}