C# .Net Framework MCQ - Answers
C# .Net Framework MCQ - Answers
Ans: A
A. Abstract methods
B. Non Abstract methods
C. Both
D. None
Ans: C
A. private
B. public
C. protected
D. internal
Ans: B
Ans : D
A. True
B. False
C. Maybe
D. Can’t say
JCET-CSE
Ans: A
Ans: C
7. Reference is a ___.
Ans: D
A. protected, public
B. private, public
C. private
D. public
Ans: C
9. What is the value returned by function compareTo( ) if the invoking string is less than the string
compared?
A. Zero
B. A value of less than zero
C. A value greater than zero
D. None of the mentioned
Ans: B
Ans: D
11. Select the two types of threads mentioned in the concept of multithreading?
A. Foreground
B. Background
C. Only foreground
D. Both foreground and background
Ans: D
Ans: A
13. If a class ‘demo’ had ‘add’ property with getting and set accessors, then which of the following
statements will work correctly?
A. math.add = 20;
B. math m = new math();
m.add = 10;
C. Console.WriteLine(math.add);
D. None of the mentioned
Ans: A
using System;
class sample
{
int i;
double k;
public sample (int ii, double kk)
{
i = ii;
k = kk;
double j = (i) + (k);
Console.WriteLine(j);
}
~sample()
{
JCET-CSE
double j = i - k;
Console.WriteLine(j);
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(9, 2.5);
}
}
A. 0 0
B. 11.5 0
C. Compile-time error
D. 11.5 6.5
Ans : D
using System;
class program
{
static void Main(string[] args)
{
int x = 8;
int b = 16;
int c = 64;
x /= c /= b;
Console.WriteLine(x + " " + b+ " " +c);
Console.ReadLine();
}
}
A. 2 16 4
B. 4 8 16
C. 2 4 8
D. 8 16 64
Ans: A
A. Protected
B. Public
C. Private
D. Default
Ans: C
17. The point at which an exception is thrown is called the _____.
A. Default point
B. Invoking point
C. Calling point
D. Throw point
Ans: D
A. Every derived class does not define its own version of the virtual method.
B. By default, the access mode for all methods in C# is virtual.
C. If a derived class, does not define its own version of the virtual method, then the one present in
the base class gets used.
D. All of the above.
Ans: B
using System;
class sample
{
public sample()
{
Console.WriteLine("constructor 1 called");
}
public sample(int x)
{
int p = 2;
int u;
u = p + x;
Console.WriteLine("constructor 2 called");
}
}
class Program
{
static void Main(string[] args)
{
sample s = new sample(4);
sample t = new sample();
Console.ReadLine();
}
}
A. constructor 1 called
constructor 2 called
JCET-CSE
B. constructor 2 called
constructor 1 called
C. constructor 2 called
constructor 2 called
D. error
Ans: B
20. Which of the following keywords is used to refer base class constructor to subclass constructor?
A. this
B. static
C. base
D. extend
Ans: C
21.Which of the following statements are TRUE about the .NET CLR?
A.Only 1 and 2
B. Only 1, 2 and 4
C. 1, 2, 3, 4
D.Only 4 and 5
E. Only 3 and 4
Answer: Option C
22.Which of the following are valid .NET CLR JIT performance counters?
A.1, 5
B. 3, 4
C. 1, 2
D.4, 5
Answer: Option B
A.1, 2
B. 2, 4
C. 4, 5
D.1, 2, 4
Answer: Option C
24.Which of the following components of the .NET framework provide an extensible set of classes that
can be used by any .NET compliant programming language?
A..NET class libraries
B. Common Language Runtime
C. Common Language Infrastructure
D.Component Object Model
E. Common Type System
Answer: Option A
A.1, 2, 3
B. 3, 5
C. 1, 4, 5
D.3, 4
JCET-CSE
Answer: Option C
26.Which of the following .NET components can be used to remove unused references from the managed
heap?
A.Common Language Infrastructure
B. CLR
C. Garbage Collector
D.Class Loader
E. CTS
Answer: Option C
Answer: Option A
1. ASP.NET Applications
2. CLR
3. Framework Class Library
4. WinForm Applications
5. Windows Services
A.1, 2
B. 2, 3
C. 3, 4
D.2, 5
Answer: Option B
Answer: Option D
Answer: Option C
Answer: Option A
33.Which of the following benefits do we get on running managed code under CLR?
A. Only 1 and 2
B. Only 2, 3 and 4
C. Only 1, 2 and 4
D. Only 4
JCET-CSE
E. All of the above
Answer: Option E
1. PIN Security
2. Code Access Security
3. Role Based Security
4. Authentication Security
5. Biorhythm Security
A.1, 4, 5
B. 2, 5
C. 2, 3
D.3, 4
Answer: Option C
1. It provides core services such as memory management, thread management, and remoting.
2. It enforces strict type safety.
3. It provides Code Access Security.
4. It provides Garbage Collection Services.
A.Only 1 and 2
B. Only 3, 4
C. Only 1, 3 and 4
D.Only 2, 3 and 4
E. All of the above
Answer: Option E
A.1, 2, 3
B. 2, 4, 5
C. 1, 3, 5
D.1, 2
Answer: Option A
A.1, 2, 3
B. 2, 4
C. 3, 4, 5
D.1, 2
Answer: Option A
A.Only 1, 2, 3
B. Only 1, 2
C. Only 1, 2, 4
D.Only 4, 5
E. All of the above
Answer: Option B
Data types
1. If the integer literal exceeds the range of byte, a compilation error will occur.
2. We cannot implicitly convert non-literal numeric types of larger storage size to byte.
3. Byte cannot be implicitly converted to float.
4. A char can be implicitly converted to only int data type.
5. We can cast the integral character codes.
A.1, 3, 5
B. 2, 4
JCET-CSE
C. 3, 5
D.1, 2, 5
Answer: Option D
Answer: Option B
Answer: Option A
Answer: Option C
1. Integer
2. Array
3. Single
4. String
5. Long
A.1, 2, 5
B. 1, 3, 5
C. 2, 4
D.3, 5
Answer: Option B
Answer: Option D
Answer: Option C
47. What will be the output of the following code snippet when it is executed?
int x = 1;
float y = 1.1f;
short z = 1;
Console.WriteLine((float) x + y * z - (x += (short) y));
A.0.1
B. 1.0
C. 1.1
D.11
Answer: Option A
48. Which of the following statements is correct about the C#.NET code snippet given below?
short s1 = 20;
short s2 = 400;
int a;
a = s1 * s2;
JCET-CSE
A.A value 8000 will be assigned to a.
B. A negative value will be assigned to a.
During arithmetic if the result exceeds the high or low value of the range the value wraps around till
C.
the other side of the range.
D.An error is reported as widening conversion cannot takes place.
An overflow error will be reported since the result of the multiplication exceeds the range of a Short
E.
Integer.
Answer: Option A
Answer: Option D
A.2, 5
B. 1, 5
C. 3, 4
D.2, 3
Answer: Option B
51. Which of the following is the correct ways to set a value 3.14 in a variable pi such that it cannot be
modified?
A.float pi = 3.14F;
B. #define pi 3.14F;
C. const float pi = 3.14F;
D.const float pi; pi = 3.14F;
E. pi = 3.14F;
Answer: Option C
52. Which of the following statements are correct about data types?
1. Each value type has an implicit default constructor that initializes the default value of that
type.
2. It is possible for a value type to contain the null value.
3. All value types are derived implicitly from System.ValueType class.
4. It is not essential that local variables in C# must be initialized before being used.
5. Variables of reference types referred to as objects and store references to the actual data.
A.1, 3, 5
B. 2, 4
C. 3, 5
D.2, 3, 4
Answer: Option A
53. Which of the following are the correct way to initialise the variables i and j to a value 10 each?
Answer: Option B
Answer: Option A
55. Which of the following statements are correct about datatypes in C#.NET?
.
1. Every datatype is either a value type or a reference type.
2. Value types are always created on the heap.
3. Reference types are always created on the stack.
JCET-CSE
4. Mapping of every value type to a type in Common Type System facilitates
Interoperability in C#.NET.
5. Every reference type gets mapped to a type in Common Type System.
A.1, 3
B. 2, 5
C. 1, 4
D.3, 4
Answer: Option C
56. Which of the following is the correct default value of a Boolean type?
A.0
B. 1
C. True
D.False
E. -1
Answer: Option D
1. Stack
2. Tree
3. SortedDictionary
4. SortedArray
Answer: Option C
58. For the code snippet shown below, which of the following statements are valid?
Answer: Option D
59. Which of the following statements are valid about generics in .NET Framework?
Answer: Option C
60. Which of the following statements is valid about generic procedures in C#.NET?
A.All procedures in a Generic class are generic.
B. Only those procedures labeled as Generic are generic.
C. Generic procedures can take at the most one generic parameter.
D.Generic procedures must take at least one type parameter.
E. None of the above.
Answer: Option D
61. For the code snippet shown below, which of the following statements are valid?
JCET-CSE
public void TestSub<M> (M arg)
{
Console.Write(arg);
}
}
class MyProgram
{
static void Main(string[] args)
{
TestIndiaBix bix = new TestIndiaBix();
bix.TestSub("IndiaBIX ");
bix.TestSub(4.2f);
}
}
A.Program will compile and on execution will print: IndiaBIX 4.2
B. A non generic class Hello cannot have generic subroutine.
C. Compiler will generate an error.
D.Program will generate a run-time exception.
E. None of the above.
Answer: Option A
62.For the code snippet given below, which of the following statements is valid?
Answer: Option A
63. For the code snippet given below, which of the following statements are valid?
public class MyContainer<T> where T: IComparabte
{
// Insert code here
}
1. Class MyContainer requires that it's type argument must implement IComparabte interface.
2. Type argument of class MyContainer must be IComparabte.
3. Compiler will report an error for this block of code.
4. This requirement on type argument is called as constraint.
Answer: Option C
64. For the code snippet given below, which of the following statements are valid?
1. Class MyContainer requires that it's type argument must implement IComparable interface.
2. Compiler will report an error for this block of code.
3. There are multiple constraints on type argument to MyContainer class.
4. Class MyContainer requires that its type argument must be a reference type and it must
implement IComparable interface.
Answer: Option B
JCET-CSE
Answer: Option C
Control Instructions
int i = 0, j = 0;
label:
i++;
j+=i;
if (i < 10)
{
Console.Write(i +" ");
goto label;
}
A.Prints 1 to 9
B. Prints 0 to 8
C. Prints 2 to 8
D.Prints 2 to 9
E. Compile error at label:.
Answer: Option A
67. Which of the following is the correct output for the C#.NET program given below?
int i = 20 ;
for( ; ; )
{
Console.Write(i + " ");
if (i >= -10)
i -= 4;
else
break;
}
A.20 16 12 84 0 -4 -8
B. 20 16 12 8 4 0
C. 20 16 12 8 4 0 -4 -8 -12
D.16 12 8 4 0
E. 16 8 0 -8
Answer: Option C
Answer: Option D
69. What is the output of the C#.NET code snippet given below?
namespace IndiabixConsoleApplication
{
public enum color
{ red, green, blue };
class SampleProgram
{
static void Main (string[ ] args)
{
color c = color.blue;
switch (c)
{
case color.red:
Console.WriteLine(color.red);
break;
case color.green:
Console.WriteLine(color.green);
break;
case color.blue:
Console.WriteLine(color.blue);
break;
}
}
}
}
A.red
B. blue
C. 0
D.1
E. 2
Answer: Option B
JCET-CSE
70. Which of the following is the correct way to rewrite the following C#.NET code snippet
given below?
int i = 0;
do
{
Console.WriteLine(i);
i+ = 1;
} while (i <= 10);
------------------------------------------
int i = 0;
do
{
A. Console.WriteLine(i);
} until (i <= 10);
int i;
B. for (i = 0; i <= 10 ; i++)
Console.WriteLine(i);
---------------------------------------
int i = 0;
while (i <= 11)
{
C. Console.WriteLine(i);
i += 1;
}
--------------------------------------------------
int i = 0;
do while ( i <= 10)
{
D. Console.WriteLine(i);
i += 1;
}
-------------------------------------
int i = 0;
do until (i <= 10)
{
E. Console.WriteLine(i);
i+=1;
}
Answer: Option B