11. Which among the following differentiates enum in C#.NET from enum in C language?
12. What will be the output of the following C# code?
class a
{
public void fun()
{
Console.WriteLine("base method");
}
}
class b: a
{
public new void fun()
{
Console.WriteLine(" derived method ");
}
}
class Program
{
static void Main(string[] args)
{
b k = new b();
k.fun();
Console.ReadLine();
}
}
class a
{
public void fun()
{
Console.WriteLine("base method");
}
}
class b: a
{
public new void fun()
{
Console.WriteLine(" derived method ");
}
}
class Program
{
static void Main(string[] args)
{
b k = new b();
k.fun();
Console.ReadLine();
}
}13. What will be the output of the following C# code?
class sample
{
public int i;
void display()
{
Console.WriteLine(i);
}
}
class sample1 : sample
{
public int j;
public void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1();
obj.i = 1;
obj.j = 2;
obj.display();
Console.ReadLine();
}
}
class sample
{
public int i;
void display()
{
Console.WriteLine(i);
}
}
class sample1 : sample
{
public int j;
public void display()
{
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
sample1 obj = new sample1();
obj.i = 1;
obj.j = 2;
obj.display();
Console.ReadLine();
}
}14. What will be the output of the following C# code?
class abc
{
public static void a()
{
console.writeline("first method");
}
public void b()
{
a();
console.writeline("second method");
}
public void b(int i)
{
console.writeline(i);
b();
}
}
class program
{
static void main()
{
abc k = new abc();
abc.a();
k.b(20);
}
}
class abc
{
public static void a()
{
console.writeline("first method");
}
public void b()
{
a();
console.writeline("second method");
}
public void b(int i)
{
console.writeline(i);
b();
}
}
class program
{
static void main()
{
abc k = new abc();
abc.a();
k.b(20);
}
}15. What will be the output of the following C# code?
class Program
{
static void Main(string[] args)
{
Console.WriteLine( vol(10));
Console.WriteLine( vol(2.5f, 5));
Console.WriteLine( vol( 5l, 4, 5));
Console.ReadLine();
}
static int vol(int x)
{
return(x * x * x);
}
static float vol(float r, int h)
{
return(3.14f * r * r * h);
}
static long vol(long l, int b, int h)
{
return(l * b * h);
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine( vol(10));
Console.WriteLine( vol(2.5f, 5));
Console.WriteLine( vol( 5l, 4, 5));
Console.ReadLine();
}
static int vol(int x)
{
return(x * x * x);
}
static float vol(float r, int h)
{
return(3.14f * r * r * h);
}
static long vol(long l, int b, int h)
{
return(l * b * h);
}
}16. What will be the output of the following C# code?
class maths
{
public int fun(int k, int y, int n)
{
Console.WriteLine(k + " " + y + " " + n);
return (k);
}
public int fun1(int t,float z)
{
Console.WriteLine(t + " " + z);
return t;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
int b = 90;
int c = 100;
int d ;
float l;
int i = obj.fun(b, c, 12);
int j = (obj.fun1(12, 14.78f));
Console.ReadLine();
}
}
class maths
{
public int fun(int k, int y, int n)
{
Console.WriteLine(k + " " + y + " " + n);
return (k);
}
public int fun1(int t,float z)
{
Console.WriteLine(t + " " + z);
return t;
}
}
class Program
{
static void Main(string[] args)
{
maths obj = new maths();
int b = 90;
int c = 100;
int d ;
float l;
int i = obj.fun(b, c, 12);
int j = (obj.fun1(12, 14.78f));
Console.ReadLine();
}
}17. What will be the output of the following C# code?
class sample
{
public int i;
public int[] arr = new int[10];
public void fun(int i, int val)
{
arr[i] = val;
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample();
s.i = 10;
sample.fun(1, 5);
s.fun(1, 5);
Console.ReadLine();
}
}
class sample
{
public int i;
public int[] arr = new int[10];
public void fun(int i, int val)
{
arr[i] = val;
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample();
s.i = 10;
sample.fun(1, 5);
s.fun(1, 5);
Console.ReadLine();
}
}18. The correct way to define a variable of type struct abc in the following C# code?
struct abc
{
public string name;
protected internal int age;
private Single sal;
}
struct abc
{
public string name;
protected internal int age;
private Single sal;
}19. Which of the following statements are correct about functions?
20. What will be the output of the following C# code?
static void Main(string[] args)
{
int X = 0;
if (Convert.ToBoolean(X = 0))
Console.WriteLine("It is zero");
else
Console.WriteLine("It is not zero");
Console.ReadLine();
}
static void Main(string[] args)
{
int X = 0;
if (Convert.ToBoolean(X = 0))
Console.WriteLine("It is zero");
else
Console.WriteLine("It is not zero");
Console.ReadLine();
}Read More Section(Classes and Objects in C Sharp)
Each Section contains maximum 100 MCQs question on Classes and Objects in C Sharp. To get more questions visit other sections.
