Classes And Objects In C Sharp - Study Mode
[#156] What will be the output of the following C# code? static void Main(string[] args)
{
int a = 5
int s = 0, c = 0
Mul (a, ref s, ref c)
Console.WriteLine(s + "t " +c)
Console.ReadLine()
}
static void Mul (int x, ref int ss, ref int cc)
{
ss = x * x
cc = x * x * x
}
Correct Answer
(B) 25 125
[#157] What will be the output of the following C# code? class z
{
public int X
public int Y
public const int c1 = 5
public const int c2 = c1 * 25
public void set(int a, int b)
{
X = a
Y = b
}
}
class Program
{
static void Main(string[] args)
{
z s = new z()
s.set(10, 20)
Console.WriteLine(s.X + " " + s.Y)
Console.WriteLine(z.c1 + " " + z.c2)
Console.ReadLine()
}
}
Correct Answer
(C) 10 20 5 125
[#158] Which C# statement should be added in function a() of class y to get output "i love csharp"? class x
{
public void a()
{
console.write("bye")
}
}
class y : x
{
public void a()
{
/* add statement here */
console.writeline(" i love csharp ")
}
}
class program
{
static void main(string[] args)
{
y obj = new obj()
obj.a()
}
}
Correct Answer
(C) base.a()
[#159] What will be the output of the following C# code? static void Main(string[] args)
{
int x = 8
int b = 16
int C = 64
x /= b /= C /= x
Console.WriteLine(x + " " + b+ " " +C)
Console.ReadLine()
}
Correct Answer
(C) 4 2 8
[#160] What will be the output of the following C# code? interface i1
{
void fun()
}
interface i2
{
void fun()
}
public class maths :i1, i2
{
void i1.fun()
{
Console.WriteLine("i1.fun")
}
void i2.fun()
{
Console.WriteLine("i2.fun")
}
}
class Program
{
static void Main(string[] args)
{
Sample obj = new Sample()
i1 i = (i1) obj
i.fun()
i2 ii = (i2) obj
ii.fun()
}
}
Correct Answer
(D) i1.fun i2.fun