logo

CuriousTab

CuriousTab

Discussion


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

    namespace CuriousTabConsoleApplication
    { 
        class Sample
        { 
            public int index; 
            public int[] arr = new int[10]; 
            
            public void fun(int i, int val)
            { 
                arr[i] = val;
            }
        }
         
        class MyProgram
        { 
            static void Main(string[] args)
            {
                Sample s = new Sample(); 
                s.index = 20; 
                Sample.fun(1, 5); 
                s.fun(1, 5); 
            } 
        } 
    }


  • Options
  • A. s.index = 20 will report an error since index is public.
  • B. The call s.fun(1, 5) will work correctly.
  • C. Sample.fun(1, 5) will set a value 5 in arr[ 1 ].
  • D. The call Sample.fun(1, 5) cannot work since fun() is not a shared function.
  • E. arr being a data member, we cannot declare it as public.

  • Correct Answer
  • The call s.fun(1, 5) will work correctly. 


  • More questions

    • 1. Which of the following statement correctly assigns a value 33 to a variable c?

      byte a = 11, b = 22, c;


    • Options
    • A. c = (byte) (a + b);
    • B. c = (byte) a + (byte) b;
    • C. c = (int) a + (int) b;
    • D. c = (int)(a + b);
    • E. c = a + b;
    • Discuss
    • 2. An enum can be declared inside a class, struct, namespace or interface.

    • Options
    • A. True
    • B. False
    • Discuss
    • 3. Which of the following statements are correct about the Collection Classes available in Framework Class Library?

    • Options
    • A. Elements of a collection cannot be transmitted over a network.
    • B. Elements stored in a collection can be retrieved but cannot be modified.
    • C. It is not easy to adopt the existing Collection classes for newtype of objects.
    • D. Elements stored in a collection can be modified only if allelements are of similar types.
    • E. They use efficient algorithms to manage the collection, thereby improving the performance of the program.
    • Discuss
    • 4. Which of the following statements is correct about a namespace used in C#.NET?

    • Options
    • A. Nested namespaces are not allowed.
    • B. Importing outer namespace imports inner namespace.
    • C. Nested namespaces are allowed.
    • D. If nested, the namespaces cannot be split across files.
    • Discuss
    • 5. Which of the following does not store a sign?

    • Options
    • A. Short
    • B. Integer
    • C. Long
    • D. Byte
    • E. Single
    • Discuss
    • 6. Which of the following is NOT an Integer?

    • Options
    • A. Char
    • B. Byte
    • C. Integer
    • D. Short
    • E. Long
    • Discuss
    • 7. Which of the following is the root of the .NET type hierarchy?

    • Options
    • A. System.Object
    • B. System.Type
    • C. System.Base
    • D. System.Parent
    • E. System.Root
    • Discuss
    • 8. Which of the following is NOT a Bitwise operator in C#.NET?

    • Options
    • A. &
    • B. |
    • C. <<
    • D. ^
    • E. ~
    • Discuss
    • 9. Which of the following is the correct default value of a Boolean type?

    • Options
    • A. 0 
    • B. 1
    • C. True
    • D. False
    • E. -1
    • Discuss
    • 10. What will be the output of the C#.NET code snippet given below?

      byte b1 = 0xAB;
      byte b2 = 0x99;
      byte temp;
      temp = (byte)~b2;
      Console.Write(temp + " ");
      temp = (byte)(b1 << b2);
      Console.Write (temp + " ");
      temp = (byte) (b2 >> 2);
      Console.WriteLine(temp);

    • Options
    • A. 102 1 38
    • B. 108 0 32
    • C. 102 0 38
    • D. 1 0 1
    • Discuss


    Comments

    There are no comments.

Enter a new Comment