What will be the output of the following C# code?
class maths
{
public maths()
{
Console.WriteLine("constructor 1 :");
}
public maths(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2: " +u);
}
}
class Program
{
static void Main(string[] args)
{
maths k = new maths(4);
maths t = new maths();
Console.ReadLine();
}
}
class maths
{
public maths()
{
Console.WriteLine("constructor 1 :");
}
public maths(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2: " +u);
}
}
class Program
{
static void Main(string[] args)
{
maths k = new maths(4);
maths t = new maths();
Console.ReadLine();
}
}A. constructor 1:
constructor 2: 6
B. constructor 2: 6
constructor 2: 6
C. constructor 2: 6
constructor 1:
D. none of the mentioned
Answer: Option C
Related Questions on Classes and Objects in C Sharp
A. A blueprint for creating objects
B. A method in C#
C. A variable in C#
D. A data type in C#
A. A method in C#
B. A variable in C#
C. An instance of a class
D. A data type in C#
A. public
B. private
C. protected
D. internal

Join The Discussion