logo

CuriousTab

CuriousTab

Discussion


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

  • Correct Answer
  • 1 and 4 Only 


  • More questions

    • 1. Which of the following statements should be added to the subroutine fun( ) if the C#.NET code snippet given below is to output 9 13?

      class BaseClass
      {
          protected int i = 13;
      }
      class Derived: BaseClass
      {
          int i = 9; 
          public void fun()
          {
              // [*** Add statement here ***]
          } 
      }

    • Options
    • A. Console.WriteLine(base.i + " " + i);
    • B. Console.WriteLine(i + " " + base.i);
    • C. Console.WriteLine(mybase.i + " " + i);
    • D. Console.WriteLine(i + " " + mybase.i);
    • E. Console.WriteLine(i + " " + this.i);
    • Discuss
    • 2. Which of the following statements are correct about Inheritance in C#.NET?

      1. A derived class object contains all the base class data.
      2. Inheritance cannot suppress the base class functionality.
      3. A derived class may not be able to access all the base class data.
      4. Inheritance cannot extend the base class functionality.
      5. In inheritance chain construction of object happens from base towards derived.

    • Options
    • A. 1, 2, 4
    • B. 2, 4, 5
    • C. 1, 3, 5
    • D. 2, 4
    • Discuss
    • 3. Which of the following is correct about the C#.NET snippet given below?

      namespace CuriousTabConsoleApplication
      { 
          class Baseclass
          { 
              public void fun()
              { 
                  Console.WriteLine("Hi" + " ");
              } 
              public void fun(int i)
              {
                  Console.Write("Hello" + " ");
              } 
          } 
          class Derived: Baseclass
          {
              public void fun()
              {
                  Console.Write("Bye" + " ");
              } 
          } 
          class MyProgram
          { 
              static void Main(string[ ] args)
              { 
                  Derived d; 
                  d = new Derived(); 
                  d.fun(); 
                  d.fun(77);
              } 
          } 
      }

    • Options
    • A. The program gives the output as: Hi Hello Bye
    • B. The program gives the output as: Bye Hello
    • C. The program gives the output as: Hi Bye Hello
    • D. Error in the program
    • Discuss
    • 4. Which of the following statements are true about the C#.NET code snippet given below?

      String s1, s2; 
      s1 = "Hi"; 
      s2 = "Hi";
      1. String objects cannot be created without using new.
      2. Only one object will get created.
      3. s1 and s2 both will refer to the same object.
      4. Two objects will get created, one pointed to by s1 and another pointed to by s2.
      5. s1 and s2 are references to the same object.

    • Options
    • A. 1, 2, 4
    • B. 2, 3, 5
    • C. 3, 4
    • D. 2, 5
    • Discuss
    • 5. Which of the following statements about a String is correct?

    • Options
    • A. A String is created on the stack.
    • B. Whether a String is created on the stack or the heap depends on the length of the String.
    • C. A String is a primitive.
    • D. A String can be created by using the statement String s1 = new String;
    • E. A String is created on the heap.
    • Discuss
    • 6. Which of the following statements are correct about the String Class in C#.NET?

      1. Two strings can be concatenated by using an expression of the form s3 = s1 + s2;
      2. String is a primitive in C#.NET.
      3. A string built using StringBuilder Class is Mutable.
      4. A string built using String Class is Immutable.
      5. Two strings can be concatenated by using an expression of the form s3 = s1&s2;

    • Options
    • A. 1, 2, 5
    • B. 2, 4
    • C. 1, 3, 4
    • D. 3, 5
    • Discuss
    • 7. Which of the following is the correct output for the C#.NET code snippet given below?

      enum color: int
      { 
          red,
          green, 
          blue = 5, 
          cyan,
          magenta = 10, 
          yellow 
      }
      Console.Write( (int) color.green + ", " ); 
      Console.Write( (int) color.yellow );

    • Options
    • A. 2, 11
    • B. 1, 11
    • C. 2, 6
    • D. 1, 5
    • E. None of the above
    • Discuss
    • 8. Which of the following statements is correct about the C#.NET code snippet given below?

      enum color : byte
      {
          red = 500,
          green = 1000,
          blue = 1500
      }

    • Options
    • A. byte values cannot be assigned to enum elements.
    • B. enum elements should always take successive values.
    • C. Since 500, 1000, 1500 exceed the valid range of byte compiler will report an error.
    • D. enum must always be of int type.
    • E. enum elements should be declared as private.
    • Discuss
    • 9. Which of the following unary operators can be overloaded?

      1. true
      2. false
      3. +
      4. new
      5. is

    • Options
    • A. 1, 2, 3
    • B. 3, 4, 5
    • C. 3 only
    • D. 5 only
    • Discuss
    • 10. Which of the following statements will correctly copy the contents of one string into another?

    • Options
    • A.
      String s1 = "String";
      String s2; 
      s2 = s1;
    • B.
      String s1 = "String" ; 
      String s2;
      s2 = String.Concat(s1, s2);
    • C.
      String s1 = "String"; 
      String s2;
      s2 = String.Copy(s1);
    • D.
      String s1 = "String"; 
      String s2;
      s2 = s1.Replace();
    • E.
      String s1 = "String"; 
      String s2;
      s2 = s2.StringCopy(s1);
    • Discuss


    Comments

    There are no comments.

Enter a new Comment