test c#

1. Which of the following is correct about params in C#

  1. By using the params keyword, a method parameter can be specified which takes a variable number of arguments or even no argument
  2. Additional parameters are not permitted after the params keyword in a method declaration
  3. Only one params keyword is allowed in a method declaration
  4. All of the above

2. If a is an array of 5 integers then which of the following is the correct way to increase its size to 10 elements

  1. int[] a = new int[5]; int[] a = new int[10];
  2. int[] a = int[5]; int[] a = int[10];
  3. int[] a = new int[5]; a.Length = 10;
  4. int[] a = new int[5]; a = new int[10];

3. Which of the following is the default access specifier of a class member variable

  1. Protected
  2. Private
  3. Public
  4. Internal

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

  1. Not inheritable
  2. Sealed
  3. Extends
  4. Inherits

5. What is indexer

  1. It allows an instance of a class to be indexed like an array
  2. It allows enumerator with class
  3. It creates index for instances of a class
  4. None of the above

6. Data type of a variable declared using var will be assigned at

  1. Runtime
  2. Application Initialization time
  3. CLR time
  4. Compile time

7. Assume class B is inherited from class A. Which of the following statements is correct about construction of an object of class B

class A { public A() { Console.WriteLine("A"); } }
	 class B : A { public B() { Console.WriteLine("B"); } }
	 B b = new B();
	
  1. While creating the object firstly the constructor of class B will be called followed by constructor of class A
  2. The constructor of only class B will be called
  3. While creating the object firstly the constructor of class A will be called followed by constructor of class B
  4. The order of calling constructors depends upon whether constructors in class A and class B are private or public

8. There are 1,000,000 key-value pairs in the dictionary. A pair with key X was added 10th in a row. For how many operations the dictionary will find and return a pair with the key X

  1. Will not find, due to the large number of elements in the dictionary
  2. For 10 operations
  3. Find only after exhaustive search
  4. In one operation
  5. Key search without knowing the value of a pair is not possible

9. Object A refers to object B, object B refers to object C, object C refers to object A. How the garbage collector works

  1. Will collect all the objects
  2. Will collect all objects only if links of type WeakReference
  3. Will not collect anyone each object has a link

10. What will be displayed in Console

void Main() {
	  var a = 3;
	  var b = 4;
	  
	  Swap(a, b);
	  Console.WriteLine($"a = {a}, b = {b}");
	}

	void Swap(int x, int y) {
	  var temp = x;
	  x = y;
	  y = temp;
	}
	
  1. a = 4, b = 3
  2. a = 3, b = 4
  3. a = 3, b = 3
  4. a = 4, b = 4