Classes And Objects In C Sharp - Study Mode

[#171] What will be the output of the following C# code? class maths
{
public int x
public double y
public int add(int a, int b)
{
x = a + b
return x
}
public int add(double c, double d)
{
y = c + d
return (int)y
}
public maths()
{
this.x = 0
this.y = 0
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
int a = 4
double b = 3.5
obj.add(a, a)
obj.add(b, b)
Console.WriteLine(obj.x + " " + obj.y)
Console.ReadLine()
}
}
Correct Answer

(D) 8, 7

[#172] What will be the Correct statement in the following C# code? interface a1
{
void f1()
int f2()
}
class a :a1
{
void f1()
{
}
int a1.f2()
{
}
}
Correct Answer

(C) The definition of f1() in class a should be void a1.f1()

[#173] What will be the output of the following C# code snippet? class maths
{
public int fact(int n)
{
int result
if (n == 2)
return 1
result = fact(n - 1) * n
return result
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()
Console.WriteLine(obj.fact(4))
Console.ReadLine()
}
}
Correct Answer

(C) 12

[#174] What will be the Correct statement in the following C# code? class sample
{
protected int index
public sample()
{
index = 0
}
}
class sample 1: sample
{
public void add()
{
index += 1
}
}
class Program
{
static void Main(string[] args)
{
sample 1 z = new sample 1()
z . add()
}
}
Correct Answer

(D) All of the mentioned

[#175] What will be the output of the following C# code? 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.i = 1
obj.j = 2
obj.display()
Console.ReadLine()
}
}
Correct Answer

(B) 2