C SHARP interview questions part 20

C SHARP interview questions part 20

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Correct way to overload +operator?

Correct Answer is : Declare sum property with get, set and normal accessors

2. Correct statement about C# code is? public class maths { public int x; public virtual void a() {  }  } public class subject : maths { new public void a() {  }  }

Correct Answer is : Declares sum property with only set accessor

3. Which of the following statements is correct?

Correct Answer is : Declare maths property with get and set accessors

4. Selecting appropriate method out of number of overloaded methods by matching arguments in terms of number ,type and order and binding that selected method to object at compile time is called?

Correct Answer is : math m = new math();

5. Wrong statement about run time polymorphism is?

Correct Answer is : Reflection

6. The correct way to implement a read only property add, in a math class is?

Correct Answer is : System.Reflection

7. The correct way to implement a write only property add in a math class?

Correct Answer is : Both Core of the reflection subsystem as it encapsulates a type & Consists of many methods and properties that can be used to obtain information about a type at runtime

8. What will be the output of following snippet of code? class number { private int num1; private int num2; public int anumber { get { return num1; } set { num1 = value; } } public int anumber1 { get { return num2; } set { num2 = value; } } } class Program { public static void Main(string[] args) { number p = new number(); p.anumber = 20; number k = new number(); k.anumber1 = 40; int m = p.anumber; int t = k.anumber1; int r = p.anumber + k.anumber1; Console.WriteLine("number = " +m); Console.WriteLine("number = " +t); Console.WriteLine("sum = " +r); Console.ReadLine(); } }

Correct Answer is : System.Reflection.MemberInfo

9. What will be the output of the following snippet of code?
  class number
  {
      private int num1 = 60;
      private int num2 = 20;
      public int anumber
      {
          get
          {
              return num1;
          }
          set
          {
              num1 = value;
          }
      }
      public int anumber1
      {
          get
          {
              return num2;
          }
          set
          {
              num2 = value;
          }
      }
  }
  class Program
  {
      public static void Main(string[] args)
      {
          number p = new number();
          number k = new number();
          int m = p.anumber;
          int t = k.anumber1;
          int r = p.anumber * k.anumber1;
          Console.WriteLine("sum = " + r);
          Console.ReadLine();
      }
  }

Correct Answer is : Both Helps in distinguishing kinds of members & Property helps in determining if member is a field, method, property or event

10. What will be the output of the following snippet of code? class number { int length = 50; public int number1 { get { return length; } set { length = value; } } } class Program { public static void Main(string[] args) { number p = new number(); p.number1 = p.number1 + 40; int k = p.number1 * 3 / 9; Console.WriteLine(k); Console.ReadLine(); } }

Correct Answer is : Module Module

11. What will be the output of the following snippet of code? class number { int length = 60; public int number1 { get { return length; } } } class Program { public static void Main(string[] args) { number p = new number(); int l; l = p.number1 + 40; int k = l * 3 / 4; Console.WriteLine(k); Console.ReadLine(); } }

Correct Answer is : All of the mentioned

12. What will be the output of the following snippet of code? class student { int []scores = new int[5] {23, 42, 54, 11, 65}; public int this[int index] { get { if (index < 5) return scores[index]; else { Console.WriteLine("invalid index"); return 0; } } set { if (index < 5) scores[index] = value; else Console.WriteLine("invalid index"); } } } class Program { public static void Main(string[] args) { student s = new student(); Console.WriteLine(s[4] + 8); Console.ReadLine(); } } a) 73 b) 37 c) 0 d) Run time error

Correct Answer is : Both Returns an array of MethodInfo objects & Returns a list of the public methods supported by the type by using GetMethods()

13. The correct way to implement the property for which property reports the error “invalid index” if user attempts to cross bounds of the array for a student class with 5 integer arrays.

Correct Answer is : All of the mentioned

14. What will be the output of the following snippet of code? class student { int []scores = new int[3] {13, 32, 24}; public int this[int index] { get { if (index < 3) return scores[index]; else { Console.WriteLine("invalid index"); return 0; } } private set { if (index < 3) scores[index] = value; else Console.WriteLine("invalid index"); } } } class Program { public static void Main(string[] args) { student s = new student(); int[] scores1 = new int[3] {8, 19, 40}; for (int i = 0; i < 3; i++) { if (scores1[i] > s[i]) { Console.WriteLine(" scores1 had greater value :" + scores1[i]); } else { Console.WriteLine("scores had greater value :" + s[i]); } } Console.ReadLine(); } }

Correct Answer is : All of the mentioned

15. Which of these is used as a default specifier for a member of the class if no access specifier is used for it?

Correct Answer is : System.IO

16. Which of these is used to access members of class before the object of that class is created?

Correct Answer is : System.IO.stream

17. Which of these base classes are accessible to the derived class members?

Correct Answer is : void close()

18. What is the process by which we can control parts of a program that can access the members of a class?

Correct Answer is : void WriteByte(byte value)

19. What will be the output of the following set of code? class sum { public int x; private int y; public void math(int a, int b) { x = a * 4; y = b; } } class Program { static void Main(string[] args) { sum p = new sum(); p.math(12, 30); Console.WriteLine(p.x + " " + p.y); Console.ReadLine(); } }

Correct Answer is : void Flush()

20. What will be the output of the following set of code? class sum { public int x; public int y; public int add (int a, int b) { x = a + b; y = x + b; return 0; } } class Program { static void Main(string[] args) { sum obj1 = new sum(); sum obj2 = new sum(); int a = 2; obj1.add(a, a + 1); obj2.add(5, a); Console.WriteLine(obj1.x + " " + obj2.y); Console.ReadLine(); } }

Correct Answer is : int Write(byte[] buffer ,int offset ,int count)

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon