Commerce

Classes And Objects In C Sharp MCQs

Practice Classes And Objects In C Sharp MCQs for competitive exams.

Classes And Objects In C Sharp MCQs

Practice questions from this topic.

Which of these data types is used by the operating system to manage the Recursion in Csharp?

  1. A. Array
  2. B. Queue
  3. C. Tree
  4. D. Stack
Report Error

Which of the following statements about objects in "C#" is correct?

  1. A. Everything you use in C# is an object, including Windows Forms and controls
  2. B. Objects have methods and events that allow them to perform actions
  3. C. All objects created from a class will occupy equal number of bytes in memory
  4. D. All of the mentioned
Report Error

Which among the following cannot be used as a datatype for an enum in C#.NET?

  1. A. short
  2. B. double
  3. C. int
  4. D. all of the mentioned
Report Error

Select the statement which should be added to the current C# code to get the output as 10 20? class baseclass { protected int a = 20; } class derived : baseclass { int a = 10; public void math() { /* add code here */ } }

  1. A. Console.writeline( a + " " + this.a)
  2. B. Console.Writeline( mybase.a + " " + a)
  3. C. console.writeline(a + " " + base.a)
  4. D. console.writeline(base.a + " " + a)
Report Error

The operator used to access member function of a class?

  1. A. :
  2. B. ::
  3. C. .
  4. D. #
Report Error

Which of the following is the correct result for the given statement in the C#.NET statement given below? p = q struct employee { private int employee id; private string city; } employee q = new employee(); employee p; p = q;

  1. A. Elements of 'q' will be copied into corresponding elements of p
  2. B. Address stored in q will get copied into p
  3. C. Address of first element of q will get copied into p
  4. D. Once assignment is over. q will go out of scope and hence get exited forever
Report Error

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(); }

  1. A. It is zero
  2. B. It is not zero
  3. C. Infinite loop
  4. D. None of the mentioned
Report Error

Which of the following statements are correct about functions?

  1. A. C# allows a function to have arguments with default values
  2. B. Redefining a method parameter in the method's body causes an exception
  3. C. C# allows function to have arguments with default values
  4. D. Omitting the return type in method definition results into exception
Report Error

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; }

  1. A. abc e = new abc()
  2. B. abc()
  3. C. abc e; e = new abc
  4. D. abc e = new abc
Report Error

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(); } }

  1. A. sample.fun(1, 5) will not work correctly
  2. B. s.i = 10 cannot work as i is 'public'
  3. C. sample.fun(1, 5) will set value as 5 in arr[1]
  4. D. s.fun(1, 5) will work correctly
Report Error

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(); } }

  1. A. 0, 0, 0 12, 14.78
  2. B. 0, 0, 0 0, 0
  3. C. 90, 100, 12 12, 14
  4. D. 90, 100, 12 12, 14.78
Report Error

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); } }

  1. A. 1000 0 100
  2. B. 0 0 100
  3. C. compile time error
  4. D. 1000 98.125 100
Report Error