Explore topic-wise MCQs in C Sharp Programming.

This section includes 65 Mcqs, each offering curated multiple-choice questions to sharpen your C Sharp Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of the following statements are correct about the C#.NET code snippet given below? sample c; c = new sample();It will create an object called sample. It will create a nameless object of the type sample. It will create an object of the type sample on the stack. It will create a reference c on the stack and an object of the type sample on the heap. It will create an object of the type sample either on the heap or on the stack depending on the size of the object.

A. 1, 3
B. 2, 4
C. 3, 5
D. 4, 5
E. None of these
Answer» C. 3, 5
2.

What is the output of following program?

A. x = 2 count = 0x = 2.2 count = 0x = 2.2 count = 0
B. x = 2 count = 0x = 2 count = 0x = 2.2 count = 0
C. x = 2 count = 0x = 2 count = 1x = 2.2 count = 0
D. x = 2 count = 0x = 2 count = 1x = 2.2 count = 2
Answer» D. x = 2 count = 0x = 2 count = 1x = 2.2 count = 2
3.

If a base class is added with few new members, its subclass must also be modified.

A. True
B. False
C. May be
D. Can't say
Answer» C. May be
4.

An object can be used to represent _________________

A. A real world entity
B. A real function
C. Some real data only
D. Some function only
Answer» B. A real function
5.

If array of objects is declared as given below, which is the limitation on objects?Class_name arrayName[size];

A. The objects will have same values
B. The objects will not be initialized individually
C. The objects can never be initialized
D. The objects will have same data
Answer» C. The objects can never be initialized
6.

What will be the output of code snippet?

A. 20, 40
B. 40, 20
C. 20, 10
D. 10, 20
Answer» D. 10, 20
7.

What will be the output of the following set of code?

A. 6, 9
B. 5, 9
C. 9, 10
D. 3, 2
Answer» C. 9, 10
8.

Select output for the set of code :

A. numbers are : 2 4 6 8 10
B. numbers are : 3 5 7 9 11
C. numbers are : 2 3 4 5 6
D. None of the mentioned
Answer» C. numbers are : 2 3 4 5 6
9.

What is the output of the following set of code?

A. 125 25
B. 25 125
C. Compile time error
D. 0 0
Answer» C. Compile time error
10.

What is the output of the code ?

A. HI HI HI
B. HI
C. Stack overflow exception
D. Compile time error
Answer» D. Compile time error
11.

Select the correct output for following set of code.

A. It is zero
B. It is not zero
C. Infinite loop
D. None of the mentioned
Answer» C. Infinite loop
12.

Output for the following set of code :

A. hi hi
B. hi
C. Stack overflow exception
D. None of the mentioned
Answer» D. None of the mentioned
13.

What is the output for selective code ?

A. Compile time error
B. hi
C. hi infinite times
D. None of the mentioned
Answer» B. hi
14.

Select the ouput for the following set of code :

A. 4 2
B. 0 4
C. 4 0
D. None of mentioned
Answer» D. None of mentioned
15.

What is the output for the following set of code :

A. 35.7810
B. 1035.00
C. 1035.78
D. None of the mentioned
Answer» D. None of the mentioned
16.

Correct way of defining constructor of the given class as and when objects of classes are created is:maths s1 = new maths();maths s2 = new maths(5, 5.4f);

A. a
B. b
C. c
D. d
Answer» B. b
17.

What is output of the code?

A. 4 3 3
B. 4 4 3
C. 4 3 4
D. 3 4 4
Answer» D. 3 4 4
18.

Select output for the following set of code.

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
Answer» B. s.i = 10 cannot work as i is ‘public’
19.

The output of code is ?

A. Code runs successfully prints nothing
B. Code runs and prints “Csharp”
C. Syntax error as t is unassigned variable which is never used
D. None of the mentioned
Answer» D. None of the mentioned
20.

Select the output for following set of code :

A. 5
B. 0
C. 20
D. 25
Answer» E.
21.

Which of the following statements are correct?1. Instance members of a class can be accessed only through an object of that class.2. A class can contain only instance data and instance member function.3. All objects created from a class will occupy equal number of bytes in memory.4. A class can contain Friend functions.5. A class is a blueprint or a template according to which objects are created.

A. 1, 3, 5
B. 2, 4
C. 3, 5
D. 2, 4, 5
Answer» B. 2, 4
22.

Select the output for the following set of code :

A. Syntax error
B. {0} is in city{1} harsh new delhi
C. harsh is in new delhi
D. Run successfully prints nothing
Answer» D. Run successfully prints nothing
23.

Which of the following is the correct way to create an object of the class Sample?1. Sample s = new Sample();2. Sample s;3. Sample s; s = new Sample();s = new Sample();

A. 1, 3
B. 2, 4
C. 1, 2, 3
D. 1, 4
Answer» B. 2, 4
24.

Which of the following statements are correct about the this reference?1. this reference can be modified in the instance member function of a class.2. Static functions of a class never receive the this reference.3. Instance member functions of a class always receive a this reference.4. this reference continues to exist even after control returns from an instance member function.5 .While calling an instance member function we are not required to pass the this reference explicitly.

A. 1, 4
B. 2, 3, 5
C. 3, 4
D. 2, 5
Answer» C. 3, 4
25.

Which of the following statements are correct about the C#.NET code snippet given below?sample c;c = new sample();1. It will create an object called sample.2. It will create a nameless object of the type sample.3. It will create an object of the type sample on the stack.4. It will create a reference c on the stack and an object of the type sample on the heap.5. It will create an object of the type sample either on the heap or on the stack depending on the size of the object.

A. 1, 3
B. 2, 4
C. 3, 5
D. 4, 5
Answer» C. 3, 5
26.

Which return statement correctly returns the output:

A. public int cube(int x){return (x + x);}
B. public int cube(int x)return (x + x);
C. public int cube(int x){return x + x;}
D. None of mentioned
Answer» B. public int cube(int x)return (x + x);
27.

When a function fun() is to receive an int, a single & a double and it is to return a decimal, then the correct way of defining this function is?

A. static fun(int i, single j, double k) { return decimal; }
B. static decimal fun(int i, single, double k) { }
C. decimal fun(int i, single j, double k) { }
D. decimal static fun(int i, single j, double k) { }
Answer» C. decimal fun(int i, single j, double k) { }
28.

Which refrence modifier is used to define reference variable?

A. &
B. ref
C. #
D. $
Answer» C. #
29.

How many values does a function return?

A. 0
B. 2
C. 1
D. any number of values
Answer» D. any number of values
30.

Which of the following statements are incorrect ?

A. public members of class can be accessed by any code in the program
B. private members of class can only be accessed by other members of the class
C. private members of class can be inherited by a sub class, and become protected members in sub class
D. protected members of a class can be inherited by a sub class, and become private members of the sub class
Answer» D. protected members of a class can be inherited by a sub class, and become private members of the sub class
31.

Output from following set of code ?

A. 0 0
B. 10.5 0
C. Compile time error
D. 10.5 5.5
Answer» E.
32.

What is output for the following set of Code ?

A. 0
B. 180
C. Compile time error
D. None of the mentioned
Answer» D. None of the mentioned
33.

Name a method which has the same name as that of class and which is used to destroy objects also called automatically when application is finally on process of being getting terminated.

A. Constructor
B. Finalize()
C. Destructor
D. End
Answer» D. End
34.

Output from selective set of code is :

A. 0
B. Code executes successfully but prints nothing
C. Compile time error
D. 180
Answer» E.
35.

Correct way to define object of sample class in which code will work correctly is:

A. abc s1 = new abc(1);
B. abc s1 = new abc();
C. abc s2 = new abc(1.4f);
D. abc s2 = new abc(1, 1.4f);
Answer» E.
36.

Which among the following is the correct statement :Constructors are used to

A. initialize the objects
B. construct the data members
C. initialize the objects & construct the data members
D. None of the mentioned
Answer» B. construct the data members
37.

What is output of the following section of code ?

A. second method20second methodfirst method
B. first method20first methodsecond method
C. first method20
D. second method20first method
Answer» C. first method20
38.

Can the method add() be overloaded in the following ways in C#?public int add() { }public float add(){ }

A. True
B. False
C. can't say
D. None of the mentioned
Answer» C. can't say
39.

Which method has the same name as that of its class?

A. delete
B. class
C. constructor
D. none of mentioned
Answer» D. none of mentioned
40.

Correct way of declaration of object of the following class is ?class name

A. name n = new name();
B. n = name();
C. name n = name();
D. n = new name();
Answer» B. n = name();
41.

Which among these access specifiers should be used for main() method?

A. private
B. public
C. protected
D. none of the mentioned
Answer» C. protected
42.

What does the following code imply ?csharp abc;abc = new charp();

A. Object creation on class csharp
B. Create an object of type csharp on heap or on stack depending on the size of object
C. create a reference c on csharp and an object of type csharp on heap
D. create an object of type csharp on stack
Answer» D. create an object of type csharp on stack
43.

Which of the following statements are correct?1. Data members ofa class are by default public.2. Data members of a class are by default private.3. Member functions of a class are by default public.4. A private function of a class can access a public function within the same class.5. Member function of a class are by default private.

A. 1, 3, 5
B. 1, 4
C. 2, 4, 5
D. 1, 2, 3
Answer» D. 1, 2, 3
44.

Select the wrong statement about ‘ref’ keyword in C#?

A. References can be called recursively
B. The ‘ref’ keyword causes arguments to be passed by reference
C. When ‘ref’ are used, any changes made to parameters in method will be reflected in variable when control is passed back to calling method
D. All of above mentioned
Answer» B. The ‘ref’ keyword causes arguments to be passed by reference
45.

Which of the following statements are correct about objects of a user-defined class called Sample?1. All objects of Sample class will always have exactly same data.2. Objects of Sample class may have same or different data.3. Whether objects of Sample class will have same or different data depends upon a Project Setting made in Visual Studio.NET.4. Conceptually, each object of Sample class will have instance data and instance member functions of the Sample class.5. All objects of Sample class will share one copy of member functions.

A. 1, 3
B. 2, 4
C. 4, 5
D. 3, 5
Answer» D. 3, 5
46.

Which of these access specifiers must be used for class so that it can be inherited by another sub class?

A. public
B. private
C. both public & private
D. none of the mentioned
Answer» B. private
47.

What is output for the following set of expression?int a+= (float) b/= (long)c

A. float
B. int
C. long
D. None of the mentioned
Answer» C. long
48.

In which of the following should the methods of a class differ if they are to be treated as overloaded methods?1. Type of arguments2. Return type of methods3. Number of arguments4. Names of methods5. Order of arguments

A. 2, 4
B. 3, 5
C. 1, 3, 5
D. 3, 4, 5
Answer» D. 3, 4, 5
49.

Which of the following statements are correct about constructors in C#.NET?1. Constructors cannot be overloaded.2. Constructors always have the name same as the name of the class.3. Constructors are never called explicitly.4. Constructors never return any value.5. Constructors allocate space for the object in memory.

A. 1, 3, 5
B. 2, 3, 4
C. 3, 5
D. 4, 5
Answer» C. 3, 5
50.

Which of the following statements are correct about static functions?1. Static functions can access only static data.2. Static functions cannot call instance functions.3. It is necessary to initialize static data.4. Instance functions can call static functions and access static data.5. this reference is passed to static functions.

A. 1, 2, 4
B. 2, 3, 5
C. 3, 4
D. 4, 5
Answer» B. 2, 3, 5