CommerceClasses 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?
- A. Array
- B. Queue
- C. Tree
- D. Stack
Correct Answer: D
Which of the following statements about objects in "C#" is correct?
- A. Everything you use in C# is an object, including Windows Forms and controls
- B. Objects have methods and events that allow them to perform actions
- C. All objects created from a class will occupy equal number of bytes in memory
- D. All of the mentioned
Correct Answer: D
Which among the following cannot be used as a datatype for an enum in C#.NET?
- A. short
- B. double
- C. int
- D. all of the mentioned
Correct Answer: B
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 */ } }
- A. Console.writeline( a + " " + this.a)
- B. Console.Writeline( mybase.a + " " + a)
- C. console.writeline(a + " " + base.a)
- D. console.writeline(base.a + " " + a)
Correct Answer: C
The operator used to access member function of a class?
- A. :
- B. ::
- C. .
- D. #
Correct Answer: C
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;
- A. Elements of 'q' will be copied into corresponding elements of p
- B. Address stored in q will get copied into p
- C. Address of first element of q will get copied into p
- D. Once assignment is over. q will go out of scope and hence get exited forever
Correct Answer: A
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(); }
- A. It is zero
- B. It is not zero
- C. Infinite loop
- D. None of the mentioned
Correct Answer: B
Which of the following statements are correct about functions?
- A. C# allows a function to have arguments with default values
- B. Redefining a method parameter in the method's body causes an exception
- C. C# allows function to have arguments with default values
- D. Omitting the return type in method definition results into exception
Correct Answer: A
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; }
- A. abc e = new abc()
- B. abc()
- C. abc e; e = new abc
- D. abc e = new abc
Correct Answer: A
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(); } }
- A. sample.fun(1, 5) will not work correctly
- B. s.i = 10 cannot work as i is 'public'
- C. sample.fun(1, 5) will set value as 5 in arr[1]
- D. s.fun(1, 5) will work correctly
Correct Answer: A
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(); } }
- A. 0, 0, 0 12, 14.78
- B. 0, 0, 0 0, 0
- C. 90, 100, 12 12, 14
- D. 90, 100, 12 12, 14.78
Correct Answer: D
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); } }
- A. 1000 0 100
- B. 0 0 100
- C. compile time error
- D. 1000 98.125 100
Correct Answer: D