Classes And Objects In C Sharp - Study Mode
[#166] What will be the output of the following C# code? class sample
{
int i
double k
public sample (int ii, double kk)
{
i = ii
k = kk
double j = (i) + (k)
Console.WriteLine(j)
}
~sample()
{
double j = i - k
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(8, 2.5)
Console.ReadLine()
}
}
Correct Answer
(D) 10.5 5.5
[#167] What will be the output of the following C# code? class maths
{
int fact(int n)
{
int result
if (n == 1)
return 1
result = fact(n - 1) * n
return result
}
}
class Output
{
static void main(String args[])
{
maths obj = new maths()
Console.WriteLine(obj.fact(4)*(3))
}
}
Correct Answer
(C) 72
[#168] What will be the output of the following C# code? namespace ConsoleApplication4
{
class A
{
public int i
public void display()
{
Console.WriteLine(i)
}
}
class B: A
{
public int j
public void display()
{
Console.WriteLine(j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.j = 1
obj.i = 8
obj.display()
Console.ReadLine()
}
}
}
Correct Answer
(C) 1
[#169] What will be the output of the following C# code? enum per
{
a,
b,
c,
d,
}
per.a = 10
Console.writeline(per.b)
Correct Answer
(D) compile time error
[#170] What will be the output of the following C# code? class sample
{
public sample()
{
Console.WriteLine("THIS IS BASE CLASS constructor")
}
}
public class sample1 : sample
{
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1()
Console.ReadLine()
}
}
Correct Answer
(C) Compile time error