Classes And Objects In C Sharp - Study Mode
[#161] 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()
}
}
Correct Answer
(C) constructor 2: 6 constructor 1:
[#162] What will be the output of the following C# code? enum colors
{
red,
black,
pink
}
colors s = colors.black
type t
t = c.GetType()
string[] str
str = Enum.GetNames(t)
Console.WriteLine(str[0])
Correct Answer
(C) red
[#163] What will be the output of the following C# code? class recursion
{
int fact(int n)
{
int result
if (n == 1)
return 1
result = fact(n - 1) * n
return result
}
}
class Program
{
public static void main(String args[])
{
recursion obj = new recursion()
Console.WriteLine(obj.fact(4))
}
}
Correct Answer
(A) 24
[#164] What will be the output of the following C# code? static void Main(string[] args)
{
int[] arr = new int[] {1, 2, 3, 4, 5}
fun1(ref arr)
Console.ReadLine()
}
static void fun1(ref int[] array)
{
for (int i = 0
i < array.Length
i++)
{
array[i] = array[i] + 5
Console.WriteLine(array[i] + " ")
}
}
Correct Answer
(A) 6 7 8 9 10
[#165] What will be the output of the following C# code? static void Main(string[] args)
{
int a = 5
fun1 (ref a)
Console.WriteLine(a)
Console.ReadLine()
}
static void fun1(ref int a)
{
a = a * a
}
Correct Answer
(D) 25