logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Datatypes See What Others Are Saying!
  • Question
  • 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;


  • Options
  • A. A value 8000 will be assigned to a.
  • B. A negative value will be assigned to a.
  • C. During arithmetic if the result exceeds the high or low value of the range the value wraps around till the other side of the range.
  • D. An error is reported as widening conversion cannot takes place.
  • E. An overflow error will be reported since the result of the multiplication exceeds the range of a Short Integer.

  • Correct Answer
  • A value 8000 will be assigned to a


  • More questions

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

      namespace CuriousTabConsoleApplication
      { 
          class Sample
          { 
              static Sample()
              { 
                  Console.Write("Sample class ");
              }
              public static void CuriousTab1()
              { 
                  Console.Write("CuriousTab1 method ");
              } 
          } 
          class MyProgram
          { 
              static void Main(string[ ] args)
              { 
                  Sample.CuriousTab1();
              } 
          } 
      }

    • Options
    • A. Sample class Tab1 method
    • B. Tab1 method
    • C. Sample class
    • D. Tab1 method Sample class
    • E. Sample class Sample class
    • Discuss
    • 2. Which of the following is the correct way to define the constructor(s) of the Sample class if we are to create objects as per the C#.NET code snippet given below?

      Sample s1 = new Sample(); 
      Sample s2 = new Sample(9, 5.6f);

    • Options
    • A.
      public Sample()
      {
          i = 0; 
          j = 0.0f;
      }
      public Sample (int ii, Single jj)
      {
          i = ii;
          j = jj;
      }
    • B.
      public Sample (Optional int ii = 0, Optional Single jj = 0.0f)
      {
          i = ii;
          j = jj;
      }
    • C.
      public Sample (int ii, Single jj)
      {
          i = ii;
          j = jj;
      }
    • D.
      Sample s;
    • E.
      s = new Sample();
    • Discuss
    • 3. Which of the following statements is correct about constructors?

    • Options
    • A. If we provide a one-argument constructor then the compiler still provides a zero-argument constructor.
    • B. Static constructors can use optional arguments.
    • C. Overloaded constructors cannot use optional arguments.
    • D. If we do not provide a constructor, then the compiler provides a zero-argument constructor.
    • Discuss
    • 4. 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;


    • Options
    • A. A value 8000 will be assigned to a.
    • B. A negative value will be assigned to a.
    • C. During arithmetic if the result exceeds the high or low value of the range the value wraps around till the other side of the range.
    • D. An error is reported as widening conversion cannot takes place.
    • E. An overflow error will be reported since the result of the multiplication exceeds the range of a Short Integer.
    • Discuss
    • 5. Which of the following is another way to rewrite the code snippet given below?

      int a = 1, b = 2, c = 0;
      if (a < b) c = a;


    • Options
    • A.
      int a = 1, b = 2, c = 0;
      c = a < b ? a : 0;
    • B.
      int a = 1, b = 2, c = 0;
      a < b ? c = a : c = 0;
    • C.
      int a = 1, b = 2, c = 0;
      a < b ? c = a : c = 0 ? 0 : 0;
    • D.
      int a = 1, b = 2, c = 0;
      a < b ? return (c): return (0);
    • E.
      int a = 1, b = 2,c = 0;
      c = a < b : a ? 0;
    • Discuss
    • 6. 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.

    • Options
    • 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
    • Discuss
    • 7. Which of the following statements correctly define .NET Framework?

    • Options
    • A. It is an environment for developing, building, deploying and executing Desktop Applications, Web 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.
    • Discuss
    • 8. Which of the following will be the correct result of the statement b = a in the C#.NET code snippet given below?

      struct Address
      {
          private int plotno;
          private String city; 
      }
      Address a = new Address(); 
      Address b; 
      b = a;

    • Options
    • A. All elements of a will get copied into corresponding elements of b.
    • B. Address stored in a will get copied into b.
    • C. Once assignment is over a will get garbage collected.
    • D. Once assignment is over a will go out of scope, hence will die.
    • E. Address of the first element of a will get copied into b.
    • Discuss
    • 9. Which of the following statements are correct about a HashTable collection?

      1. It is a keyed collection.
      2. It is a ordered collection.
      3. It is an indexed collection.
      4. It implements a IDictionaryEnumerator interface in its inner class.
      5. The key - value pairs present in a HashTable can be accessed using the Keys and Values properties of the inner class that implements the IDictionaryEnumerator interface.

    • Options
    • A. 1 and 2 only
    • B. 1, 2 and 3 only
    • C. 4 and 5 only
    • D. 1, 4 and 5 only
    • E. All of the above
    • Discuss
    • 10. Which of the following statements are correct about the C#.NET code snippet given below?

          int[] a = {11, 3, 5, 9, 4}; 
      1. The array elements are created on the stack.
      2. Refernce a is created on the stack.
      3. The array elements are created on the heap.
      4. On declaring the array a new array class is created which is derived from System.Array Class.
      5. Whether the array elements are stored in the stack or heap depends upon the size of the array.

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


    Comments

    There are no comments.

Enter a new Comment