0% found this document useful (0 votes)
63 views

C# Objective Questions: 1. Consider The Following Code

The document contains 20 multiple choice questions about C# concepts like data types, operators, classes, interfaces, inheritance, exceptions, delegates and generics. Some key points covered are: - Char can be implicitly converted to int - Interfaces can contain properties, methods and events - Finally blocks are always executed to perform cleanup - Generics allow types (like collection elements) to be specified at runtime rather than compile time - Delegates are type-safe and can call multiple methods

Uploaded by

Shruti Kukkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

C# Objective Questions: 1. Consider The Following Code

The document contains 20 multiple choice questions about C# concepts like data types, operators, classes, interfaces, inheritance, exceptions, delegates and generics. Some key points covered are: - Char can be implicitly converted to int - Interfaces can contain properties, methods and events - Finally blocks are always executed to perform cleanup - Generics allow types (like collection elements) to be specified at runtime rather than compile time - Delegates are type-safe and can call multiple methods

Uploaded by

Shruti Kukkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

C# Objective Questions

1. Consider the following code:


static void Main(string[] args)
{
char i = 'A';
int j = i;
Console.Write(j.ToString());
}
A. Compilation error
B. Run-time error
C. A
D. 65

2. Which of the following statements is correct about the C#.NET code snippet given below?

int d;
d = Convert.ToInt32( !(30 < 20) );

A. A value 0 will be assigned to d.


B. A value 1 will be assigned to d.
C. A value -1 will be assigned to d.
D. The code reports an error.
E. The code snippet will work correctly if ! is replaced by Not

3. What will be the output of the C#.NET code snippet given below?

int num = 1, z = 5;
if (!(num <= 0))
Console.WriteLine( ++num + z++ + " " + ++z );
else
Console.WriteLine( --num + z-- + " " + --z );

A. 5 6
B. 6 5
C. 6 6
D. 7 7

4. Which of the following can be declared in an interface?

1. Properties
2. Methods
3. Enumerations
4. Events
5. Structures

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

5. Which of the following statements is correct about an interface used in C#.NET?

1. One class can implement only one interface.


2. In a program if one class implements an interface then no other class in the same
program can implement this interface.
3. From two base interfaces a new interface cannot be inherited.
E.4. Properties can be declared inside an interface.
5. Interfaces cannot be inherited.

6. A derived class can stop virtual inheritance by declaring an override as

1. Inherits
2. Extends
3. inheritable
4. not inheritable
5. Sealed

7. Which of the following statements is correct?

1. Static methods can be a virtual method.


2. Abstract methods can be a virtual method.
3. It is necessary to override a virtual method.
4. When overriding a method, the names and type signatures of the override method must
be the same as the virtual method that is being overriden.
5. We can override virtual as well as non-virtual methods.

8. 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

9. Which of the following is NOT a .NET Exception class?

1. Exception
2. StackMemoryException
3. DivideByZeroException
4. OutOfMemoryException
5. InvalidOperationException

10. Which of the following statements are correct about exception handling in C#.NET?

1. If an exception occurs then the program terminates abruptly without getting any chance
to recover from the exception.
2. No matter whether an exception occurs or not, the statements in the finally clause (if
present) will get executed.
3. A program can contain multiple finally clauses.
4. A finally clause is written outside the try block.
5. finally clause is used to perform clean up operations like closing the network/database
connections.

11. Which of the following statements is correct about constructors in C#.NET?

1. A constructor cannot be declared as private.


2. A constructor cannot be overloaded.
3. A constructor can be a static constructor.
4. A constructor cannot access static data.
5. this reference is never passed to a constructor.

12. Which of the following statements are correct about functions used in C#.NET?

1. Function definitions cannot be nested.


2. Functions can be called recursively.
3. If we do not return a value from a function then a value -1 gets returned.
4. To return the control from middle of a function exit function should be used.
5. Function calls can be nested.

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

13. How many values is a function capable of returning?

A. 1
B. 0
C. Depends upon how many params arguments does it use.
D. Any number of values.
E. Depends upon how many ref arguments does it use.

14. 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

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

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

16. Which of the following statements is correct about properties used in C#.NET?

A. A property can simultaneously be read only or write only.


B. A property can be either read only or write only.
C. A write only property will have only get accessor.
D. A write only property will always return a value.

17. 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?

1. .NET class libraries


2. Common Language Runtime
3. Common Language Infrastructure
4. Component Object Model
5. Common Type System
18. Which of the following .NET components can be used to remove unused references
from the managed heap?

1. Common Language Infrastructure


2. CLR
3. Garbage Collector
4. Class Loader
5. CTS

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

1. Unmanaged
2. Distributed
3. Legacy
4. Managed Code
5. Native Code

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

1. Delegates are reference types.


2. Delegates are object oriented.
3. Delegates are type-safe.
4. Delegates serve the same purpose as function pointers in C and pointers to member
function operators in C++.
5. Only one method can be called using a delegate.

You might also like