Section 1: Multiple Choice

1. What is an enum in C#?

  1. A collection of methods

  2. A data type that stores multiple values in a list

  3. A way to define a set of named integer constants

  4. A class that can have multiple instances

chevron-rightAnswerhashtag
  1. A way to define a set of named integer constants


2. What is the default access modifier in C#?

  1. public

  2. private

  3. protected

  4. internal

chevron-rightAnswerhashtag
  1. private


3. What does sealed do in a class declaration?

  1. Prevents it from being instantiated

  2. Prevents it from being inherited

  3. Prevents modification of its properties

  4. Turns it into a static class

chevron-rightAnswerhashtag
  1. Prevents it from being inherited


4. Which of these is a correct way to define a property in C#?

  1. public string Name { get; set; }

  2. public string Name() { get; set; }

  3. public string Name = "default";

  4. private string Name { get };

chevron-rightAnswerhashtag
  1. public string Name { get; set; }


5. How do you declare an interface in C#?

  1. class IExample {}

  2. interface IExample {}

  3. public static IExample {}

  4. abstract IExample {}

chevron-rightAnswerhashtag
  1. interface IExample {}


6. What will this code output?

  1. 10

  2. 20

  3. Null

  4. Compilation error

chevron-rightAnswerhashtag
  1. 10


7. What is the default value of an uninitialised bool variable in C#?

  1. null

  2. true

  3. false

  4. 0

chevron-rightAnswerhashtag
  1. false


8. What does readonly do in C#?

  1. Makes a variable accessible only inside a class

  2. Allows modification only in the constructor

  3. Prevents modification entirely

  4. Applies to only static variables

chevron-rightAnswerhashtag
  1. Allows modification only in the constructor


9. What happens if you do not explicitly set a value for an enum member?

  1. It defaults to null

  2. It takes the value 0 and increments for subsequent numbers

  3. It must be set explicitly

  4. It causes a compilation error

chevron-rightAnswerhashtag
  1. It takes the value 0 and increments for subsequent numbers


10. How do you call a method in another class?

  1. ClassName.MethodName();

  2. MethodName.ClassName();

  3. this.MethodName();

  4. new MethodName();

chevron-rightAnswerhashtag
  1. ClassName.MethodName();

Last updated