Classes And Objects In C Sharp - Study Mode

[#151] What will be the output of the following C# code? enum color:int
{
red,
green,
blue = 5,
cyan,
pink = 10,
brown
}
console.writeline((int)color.green)

console.writeline((int)color.brown)

Correct Answer

(C) 1 11

[#152] What will be the output of the following C# code? class maths
{
int i

public maths(int ii)
{
ii = -25

int g

g = ii > 0 ? ii : ii * -1

Console.WriteLine(g)

}
}
class maths1 :maths
{
public maths1(int ll) :base(ll)
{
ll = -1000

Console.WriteLine((ll > 0 ? ll : ll * -1))

}
}
class Program
{
static void Main(string[] args)
{
maths1 p = new maths1(6)

Console.ReadLine()

}
}
Correct Answer

(C) 25 1000

[#153] What will be the output of the following C# code? class maths
{
public static void fun1()
{
Console.WriteLine("method 1 :")

}
public void fun2()
{
fun1()

Console.WriteLine("method 2 :")

}
public void fun2(int k)
{
Console.WriteLine(k)

fun2()

}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths()

maths.fun1()

obj.fun2(20)

Console.ReadLine()

}
}
Correct Answer

(D) method 1: 20 method 1: method 2:

[#154] What will be the output of the following C# code? static void Main(string[] args)
{
int a = 10 , b = 20

Console.WriteLine("Result before swap is: "+ a +" "+b)

swap(ref a, ref b)

Console.ReadLine()

}
static void swap(ref int i, ref int j)
{
int t

t = i

i = j

j = t

Console.WriteLine("Result after swap is:"+ i +" "+j)

}
Correct Answer

(B) Result before swap is: 10 20 Result after swap is:20 10

[#155] What will be the output of the following C# code? class A
{
public int i
private int j
}
class B :A
{
void display()
{
base.j = base.i + 1
Console.WriteLine(base.i + " " + base.j)
}
}
class Program
{
static void Main(string[] args)
{
B obj = new B()
obj.i = 1
obj.j = 2
obj.display()
Console.ReadLine()
}
}
Correct Answer

(D) compile time error