Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
class test
{
public void print()
{
Console.WriteLine(“Csharp:”);
}
}
class Program
{
static void Main(string[] args)
{
test t;
t.print();
Console.ReadLine();
}
}

What will be the output of the following C# code?
class test
{
public void print()
{
Console.WriteLine(“Csharp:”);
}
}
class Program
{
static void Main(string[] args)
{
test t;
t.print();
Console.ReadLine();
}
}
a) Code runs successfully prints nothing
b) Code runs and prints “Csharp”
c) Syntax error as t is unassigned variable which is never used
d) None of the mentioned

Answer: c
Explanation: object of class test should be declared as test t = new test();
test t = new test();
t.print();
Console.ReadLine();

Join The Discussion