logo

CuriousTab

CuriousTab

Discussion


Home C# Programming Constructors See What Others Are Saying!
  • Question
  • Which of the following statements are correct about the C#.NET code snippet given below?

    class Sample
    {
        static int i;
        int j;
        public void proc1()
        {
            i = 11; 
            j = 22;
        }
        public static void proc2()
        {
            i = 1;
            j = 2;
        }
        static Sample()
        {
            i = 0; 
            j = 0;
        }
    }


  • Options
  • A. i cannot be initialized in proc1().
  • B. proc1() can initialize i as well as j.
  • C. j can be initialized in proc2().
  • D. The constructor can never be declared as static.
  • E. proc2() can initialize i as well as j.

  • Correct Answer
  • proc1() can initialize i as well as j


  • More questions

    • 1. If Sample class has a Length property with get and set accessors then which of the following statements will work correctly?

      1. Sample.Length = 20;
      2. Sample m = new Sample(); 
        m.Length = 10;
      3. Console.WriteLine(Sample.Length);
      4. Sample m = new Sample(); 
        int len;
        len = m.Length;
      5. Sample m = new Sample(); 
        m.Length = m.Length + 20;

    • Options
    • A. 1, 3
    • B. 2, 4, 5
    • C. 4 only
    • D. 3, 5
    • Discuss
    • 2. Which of the following statements are correct about exception handling in C#.NET?

      1. try blocks cannot be nested.
      2. In one function, there can be only one try block.
      3. An exception must be caught in the same function in which it is thrown.
      4. All values set up in the exception object are available in the catch block.
      5. While throwing a user-defined exception multiple values can be set in the exception, object.

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

      interface IMyInterface 
      {
          void fun1(); 
          void fun2();
      }
      class MyClass: IMyInterface
      { 
          private int i; 
          void IMyInterface.fun1()
          { 
              // Some code
          } 
      }

    • Options
    • A. Class MyClass is an abstract class.
    • B. Class MyClass cannot contain instance data.
    • C. Class MyClass fully implements the interface IMyInterface.
    • D. Interface IMyInterface should be inherited from the Object class.
    • E. The compiler will report an error since the interface IMyInterface is only partially implemented.
    • Discuss
    • 4. What will be the output of the C#.NET code snippet given below?

      int i, j = 1, k;
      for (i = 0; i < 5; i++)
      {
          k = j++ + ++j;
          Console.Write(k + " ");
      }

    • Options
    • A. 8 4 16 12 20
    • B. 4 8 12 16 20
    • C. 4 8 16 32 64
    • D. 2 4 6 8 10
    • Discuss
    • 5. 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.

    • Options
    • A. 1 only
    • B. 2 only
    • C. 2 and 5 only
    • D. 3 and 4 only
    • E. None of the above
    • Discuss
    • 6. Which of the following will be the correct output for the C#.NET program given below?

      namespace CuriousTabConsoleApplication
      { 
          struct Sample
          { 
              public int i;
          }
          class MyProgram
          { 
              static void Main(string[] args)
              {
                  Sample x = new Sample(); 
                  x.i = 10; 
                  fun(ref x); 
                  Console.Write(x.i + " ");
              }
              public static void fun(ref Sample y)
              { 
                  y.i = 20;
                  Console.Write(y.i + " "); 
              } 
          } 
      }

    • Options
    • A. 20 10
    • B. 10 20
    • C. 10 10
    • D. 20 20
    • E. None of the above
    • Discuss
    • 7. Which of the following statements are correct about the exception reported below?
      Unhandled Exception: System.lndexOutOfRangeException:
      Index was outside the bounds of the array.
      at CuriousTabConsoleApplication.Program.Main(String[] args) in
      D:\ConsoleApplication\Program.cs:line 14

      1. The program did not handle an exception called IndexOutOfRangeException.
      2. The program execution continued after the exception occurred.
      3. The exception occurred in line number 14.
      4. In line number 14, the program attempted to access an array element which was beyond the bounds of the array.
      5. The CLR could not handle the exception.

    • Options
    • A. 1 only
    • B. 1, 2 and 3 only
    • C. 2 and 5 only
    • D. 1, 3 and 4 only
    • E. None of the above
    • Discuss
    • 8. Which of the following statements is incorrect about delegate?

    • Options
    • A. Delegates are reference types.
    • B. Delegates are object oriented.
    • C. Delegates are type-safe.
    • D. Delegates serve the same purpose as function pointers in C and pointers to member function operators in C++.
    • E. Only one method can be called using a delegate.
    • Discuss
    • 9. Which of the following jobs are NOT performed by Garbage Collector?

      1. Freeing memory on the stack.
      2. Avoiding memory leaks.
      3. Freeing memory occupied by unreferenced objects.
      4. Closing unclosed database collections.
      5. Closing unclosed files.

    • Options
    • A. 1, 2, 3
    • B. 3, 5
    • C. 1, 4, 5
    • D. 3, 4
    • Discuss
    • 10. Which of the following statements is correct about the array declaration given below?

         int[][][] intMyArr = new int[2][][];

    • Options
    • A. intMyArr refers to a 2-D jagged array containing 2 rows.
    • B. intMyArr refers to a 2-D jagged array containing 3 rows.
    • C. intMyArr refers to a 3-D jagged array containing 2 2-D jagged arrays.
    • D. intMyArr refers to a 3-D jagged array containing three 2-D jagged arrays.
    • E. intMyArr refers to a 3-D jagged array containing 2 2-D rectangular arrays.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment