100% found this document useful (6 votes)
7K views

C# .Net Framework MCQ - Answers

1. This document contains 33 multiple choice questions and answers about C# .NET Framework. 2. The questions cover topics such as CLR, abstract classes, interfaces, delegates, structures, constructors, references, properties, operators, threads, exceptions, inheritance, and garbage collection. 3. The correct answers are provided for each question to test understanding of key concepts in the .NET Framework and C# programming language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
7K views

C# .Net Framework MCQ - Answers

1. This document contains 33 multiple choice questions and answers about C# .NET Framework. 2. The questions cover topics such as CLR, abstract classes, interfaces, delegates, structures, constructors, references, properties, operators, threads, exceptions, inheritance, and garbage collection. 3. The correct answers are provided for each question to test understanding of key concepts in the .NET Framework and C# programming language.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

JAYA COLLEGE OF ENGG & TECHNOLOGY

DEPARTMENT COMPUTER SCIENCE AND ENGINEERING

C# .NET FRAMEWORK MCQ_ANSWERS

1. CLR is the .Net equivalent of _____.

A. Java Virtual machine


B. Common Language Runtime
C. Common Type System
D. Common Language Specification

Ans: A

2. Abstract class contains _____.

A. Abstract methods
B. Non Abstract methods
C. Both
D. None

Ans: C

3. The default scope for the members of an interface is _____.

A. private
B. public
C. protected
D. internal

Ans: B

4. Which of the following statements is incorrect about delegate?

A. Delegates are reference types.


B. Delegates are object-oriented.
C. Delegates are type-safe.
D. Only one can be called using a delegate.

Ans : D

5. The space required for structure variables is allocated on the stack.

A. True
B. False
C. Maybe
D. Can’t say

JCET-CSE
Ans: A

6. Which of the following is incorrect about constructors?

A. Defining of constructors can be implicit or explicit.


B. The calling of constructors is explicit.
C. Implicit constructors can be parameterized or parameterless.
D. Explicit constructors can be parameterized or parameterless.

Ans: C

7. Reference is a ___.

A. Copy of class which leads to memory allocation.


B. Copy of class that is not initialized.
C. Pre-defined data type.
D. Copy of class creating by an existing instance.

Ans: D

8. The data members of a class by default are?

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

10. The correct way to overload +operator?

A. public sample operator + (sample a, sample b)


B. public abstract operator + (sample a, sample b)
C. public static operator + (sample a, sample b)
D. all of the mentioned above

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

12. Choose the wrong statement about properties used in C#.Net?

A. Each property consists of accessor as getting and set.


B. A property cannot be either read or write-only.
C. Properties can be used to store and retrieve values to and from the data members of a class.
D. Properties are like actual methods that work like data members.

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

14. What will be the output of the following code snippet?

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

15. What will be the output of the following code snippet?

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

16. Struct’s data members are ___ by default.

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

18. Which of the following statements are correct for C# language?

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

19. What will be the output of the following code snippet?

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?

1. It provides a language-neutral development & execution environment.


2. It ensures that an application would not be able to access memory that it is not authorized to
access.
3. It provides services to run "managed" applications.
4. The resources are garbage collected.
5. It provides services to run "unmanaged" applications.

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?

1. Total memory used for JIT compilation


2. Average memory used for JIT compilation
3. Number of methods that failed to compile with the standard JIT
4. Percentage of processor time spent performing JIT compilation
5. Percentage of memory currently dedicated for JIT compilation

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

23.Which of the following are NOT true about .NET Framework?

1. It provides a consistent object-oriented programming environment whether object code is stored


and executed locally, executed locally but Internet-distributed, or executed remotely.
2. It provides a code-execution environment that minimizes software deployment and versioning
conflicts.
3. It provides a code-execution environment that promotes safe execution of code, including code
created by an unknown or semi-trusted third party.
4. It provides different programming models for Windows-based applications and Web-based
applications.
5. It provides an event driven programming model for building Windows Device Drivers.

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

25.Which of the following jobs are NOT performed by Garbage Collector?

1. Freeing memory on the stack.


2. Avoiding memory leaks.
3. Freeing memory occupied by unreferenced objects.
4. Closing unclosed database collections.
5. Closing unclosed files.

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

27.Which of the following statements correctly define .NET Framework?


It is an environment for developing, building, deploying and executing Desktop Applications, Web
A.
Applications and Web Services.
B. It is an environment for developing, building, deploying and executing only Web Applications.
C. It is an environment for developing, building, deploying and executing Distributed Applications.
D.It is an environment for developing, building, deploying and executing Web Services.
E. It is an environment for development and execution of Windows applications.

Answer: Option A

28.Which of the following constitutes the .NET Framework?

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

29.Which of the following assemblies can be stored in Global Assembly Cache?


A.Private Assemblies
B. Friend Assemblies
C. Shared Assemblies
D.Public Assemblies
E. Protected Assemblies
Answer: Option C

30. Code that targets the Common Language Runtime is known as


A.Unmanaged
B. Distributed
C. Legacy
D.Managed Code
E. Native Code

Answer: Option D

31.Which of the following statements is correct about the .NET Framework?


A..NET Framework uses DCOM for achieving language interoperability.
B. .NET Framework is built on the DCOM technology.
C. .NET Framework uses DCOM for making transition between managed and unmanaged code.
D..NET Framework uses DCOM for creating unmanaged applications.
E. .NET Framework uses COM+ services while creating Distributed Applications.

Answer: Option C

32.Which of the following is the root of the .NET type hierarchy?


A.System.Object
B. System.Type
C. System.Base
D.System.Parent
E. System.Root

Answer: Option A

33.Which of the following benefits do we get on running managed code under CLR?

1. Type safety of the code running under CLR is assured.


2. It is ensured that an application would not access the memory that it is not authorized to
access.
3. It launches separate process for every application running under it.
4. The resources are Garbage collected.

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

35.Which of the following security features can .NET applications avail?

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

36.Which of the following jobs are done by Common Language Runtime?

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

37.Which of the following statements are correct about a .NET Assembly?

1. It is the smallest deployable unit.


2. Each assembly has only one entry point - Main(), WinMain() or DLLMain().
3. An assembly can be a Shared assembly or a Private assembly.
4. An assembly can contain only code and data.
5. An assembly is always in the form of an EXE file.

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

Answer: Option A

38.Which of the following statements are correct about JIT?

1. JIT compiler compiles instructions into machine code at run time.


2. The code compiler by the JIT compiler runs under CLR.
3. The instructions compiled by JIT compilers are written in native code.
4. The instructions compiled by JIT compilers are written in Intermediate Language (IL) code.
5. The method is JIT compiled even if it is not called

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

Answer: Option A

39.Which of the following are parts of the .NET Framework?

1. The Common Language Runtime (CLR)


2. The Framework Class Libraries (FCL)
3. Microsoft Published Web Services
4. Applications deployed on IIS
5. Mobile Applications

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

40.Which of the following statements are correct about 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

41.Which of the following is an 8-byte Integer?


A.Char
B. Long
C. Short
D.Byte
E. Integer

Answer: Option B

42.Which of the following is NOT an Integer?


A.Char
B. Byte
C. Integer
D.Short
E. Long

Answer: Option A

43.Which of the following statements is correct?


A.Information is never lost during narrowing conversions.
B. The CInteger() function can be used to convert a Single to an Integer.
C. Widening conversions take place automatically.
D.Assigning an Integer to an Object type is known as Unboxing.
E. 3.14 can be treated as Decimal by using it in the form 3.14F.

Answer: Option C

44.Which of the following are value types?

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

45.. Which of the following does not store a sign?


A.Short
B. Integer
C. Long
D.Byte
E. Single

Answer: Option D

46. What is the size of a Decimal?


A.4 byte
B. 8 byte
C. 16 byte
D.32 byte

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

49. Which of the following is the correct size of a Decimal datatype?


A.8 Bytes
B. 4 Bytes
C. 10 Bytes
D.16 Bytes
E. None of the above.

Answer: Option D

50.. Which of the following statements are correct?

1. We can assign values of any type to variables of type object.


2. When a variable of a value type is converted to object, it is said to be unboxed.
3. When a variable of type object is converted to a value type, it is said to be boxed.
4. Boolean variable cannot have a value of null.
5. When a value type is boxed, an entirely new object must be allocated and constructed.

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?

1. int i = 10; int j = 10;


2. int i, j;
3. i = 10 : j = 10;
4. int i = 10, j = 10;
5. int i, j = 10;
6. int i = j = 10;
A.2, 4
B. 1, 3
C. 3, 5
D.4, 5

Answer: Option B

54. Which of the following statement correctly assigns a value 33 to a variable c?

byte a = 11, b = 22, c;


A.c = (byte) (a + b);
B. c = (byte) a + (byte) b;
C. c = (int) a + (int) b;
D.c = (int)(a + b);
E. c = a + 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

Generics - General Questions

57.Which one of the following classes are present System.Collections.Generic namespace?

1. Stack
2. Tree
3. SortedDictionary
4. SortedArray

A.1 and 2 only


B. 2 and 4 only
C. 1 and 3 only
D.All of the above
E. None of the above

Answer: Option C

58. For the code snippet shown below, which of the following statements are valid?

public class Generic<T>


{
public T Field;
public void TestSub()
{
T i = Field + 1;
}
}
class MyProgram
{
static void Main(string[] args)
{
Generic<int> gen = new Generic<int>();
gen.TestSub();
}
}
A.Addition will produce result 1.
B. Result of addition is system-dependent.
C. Program will generate run-time exception.
D.Compiler will report an error: Operator '+' is not defined for types T and int.
E. None of the above.

Answer: Option D

59. Which of the following statements are valid about generics in .NET Framework?

1. Generics is a language feature.


2. We can create a generic class, however, we cannot create a generic interface in C#.NET.
3. Generics delegates are not allowed in C#.NET.
4. Generics are useful in collection classes in .NET framework.
5. None of the above

A.1 and 2 Only


B. 1, 2 and 3 Only
C. 1 and 4 Only
D.All of the above
E. None of the above

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?

public class TestIndiaBix


{

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?

public class Generic<T>


{
public T Field;
}
class Program
{
static void Main(string[ ] args)
{
Generic<String> g = new Generic<String>();
g.Field = "Hello";
Console.WriteLine(g.Field);
}
}
A.It will print string "Hello" on the console.
B. Name Generic cannot be used as a class name because it's a keyword.
C. Compiler will give an error.
D.Member Field of class Generic is not accessible directly.
E. None of the above.

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.

A.1 and 2 Only


B. 1, 2 and 3 Only
C. 1 and 4 Only
D.All of the above
E. None of the above

Answer: Option C

64. For the code snippet given below, which of the following statements are valid?

public class MyContainer<T> where T: class, IComparable


{
//Insert code here
}

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.

A.1 and 2 Only


B. 3 and 4 Only
C. 2 and 3 Only
D.All of the above
E. None of the above

Answer: Option B

65. Which of the following statements is valid about advantages of generics?


A.Generics shift the burden of type safety to the programmer rather than compiler.
B. Generics require use of explicit type casting.
C. Generics provide type safety without the overhead of multiple implementations.
D.Generics eliminate the possibility of run-time errors.
E. None of the above.

JCET-CSE
Answer: Option C

Control Instructions

66.What does the following C#.NET code snippet will print?

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

68. Which of the following statements is correct?


A.It is not possible to extend the if statement to handle multiple conditions using the else-if
arrangement.
The switch statement can include any number of case instances with two case statements
B.
having the same value.
A jump statement such as a break is required after each case block excluding the last block
C.
if it is a default statement.
The if statement selects a statement for execution based on the value of a Boolean
D.
expression.
E. C# always supports an implicit fall through from one case label to another.

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

You might also like