Classes And Objects In C Sharp - Study Mode
[#146] What will be the output of the following C# code? enum letters
{
a,
b,
c
}
letters l
l = letters.a
Console.writeline(l)
Correct Answer
(C) a
[#147] What will be the output of the following C# code? static void Main(string[] args)
{
int y = 3
y++
if (y <= 5)
{
Console.WriteLine("hi")
Main(args)
}
Console.ReadLine()
}
Correct Answer
(C) Stack overflow exception
[#148] What will be the output of the following C# code? class maths
{
public int fun(int ii)
{
return(ii > 0 ? ii :ii * -1)
}
public long fun(long ll)
{
return(ll > 0 ? ll :ll * -1)
}
public double fun( double dd)
{
return(dd > 0 ? dd :dd * -1)
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int i = -25
int j
long l = -100000l
long m
double d = -12.34
double e
j = obj.fun(i)
m = obj.fun(l)
e = obj.fun(d)
Console.WriteLine(j + " " + m + " " + e)
Console.ReadLine()
}
}
Correct Answer
(C) 25 100000 12.34
[#149] What will be the output of the following C# code? class maths
{
public int fun1(int k)
{
k = 20
return k
}
public Single fun1(float t)
{
t = 3.4f
return t
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int i
i = obj.fun1(30)
Console.WriteLine(i)
Single j
j = obj.fun1(2.5f)
Console.WriteLine(j)
Console.ReadLine()
}
}
Correct Answer
(D) 20 3.4f
[#150] What will be the output of the following C# code? interface calc
{
void cal(int i)
}
public class maths :calc
{
public int x
public void cal(int i)
{
x = i * i
}
}
class Program
{
public static void Main(string[] args)
{
display arr = new display()
arr.x = 0
arr.cal(2)
Console.WriteLine(arr.x)
Console.ReadLine()
}
}
Correct Answer
(C) 4