logo

CuriousTab

CuriousTab

Discussion


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

  • Correct Answer
  • The program gives the output as: Bye Hello 


  • More questions

    • 1. Attributes can be applied to

      1. Method
      2. Class
      3. Assembly
      4. Namespace
      5. Enum

    • Options
    • A. 1 and 2 only
    • B. 1, 2 and 3
    • C. 4 and 5 only
    • D. All of the above
    • E. None of the above
    • Discuss
    • 2. Which of the following statements is correct about the C#.NET program given below if a value "6" is input to it?

      using System;
      namespace CuriousTabConsoleApplication
      {
          class MyProgram
          {
              static void Main (string[] args)
              {
                  int index; 
                  int val = 66; 
                  int[] a = new int[5]; 
                  try
                  {
                      Consote.Write("Enter a number: "); 
                      index = Convert.ToInt32(Console.ReadLine()); 
                      a[index] = val;
                  }
                  catch(Exception e)
                  {
                      Console.Write("Exception occurred ");
                  }
                  Console.Write("Remaining program ");
              }
          }
      }

    • Options
    • A. It will output: Exception occurred
    • B. It will output: Remaining program
    • C. It will output: Exception occurred Remaining program
    • D. It will output: Remaining program Exception occurred
    • E. The value 66 will get assigned to a[6].
    • Discuss
    • 3. If a base class and a derived class each include a member function with the same name, the member function of the derived class will be called by an object of the derived class

    • Options
    • A. True
    • B. False
    • Discuss
    • 4. Which of the following statements are valid about generics in .NET Framework?

      1. Generics is a language feature.
      2. We can create a generic class, however, we cannot create a generic interface in C#.NET.
      3. Generics delegates are not allowed in C#.NET.
      4. Generics are useful in collection classes in .NET framework.
      5. None of the above

    • 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
    • 5. What will be the output of the C#.NET code snippet given below?

      namespace CuriousTabConsoleApplication
      {
          class SampleProgram
          {
              static void Main(string[ ] args)
              {
                  int i = 5;
                  int j;
                  fun1(ref i);
                  fun2(out j);
                  Console.WriteLine(i + ", " + j);
              }
              static void funl(ref int x)
              {
                  x = x * x;
              }
              static void fun2(out int x)
              {
                  x = 6; 
                  x = x * x; 
              }
          }
      }

    • Options
    • A. 5, 6
    • B. 5, 36
    • C. 25, 36
    • D. 25, 0
    • E. 5, 0
    • Discuss
    • 6. Which of the following statements is correct about Interfaces used in C#.NET?

    • Options
    • A. All interfaces are derived from an Object class.
    • B. Interfaces can be inherited.
    • C. All interfaces are derived from an Object interface.
    • D. Interfaces can contain only method declaration.
    • E. Interfaces can contain static data and methods.
    • Discuss
    • 7. Which of the following statements is valid about advantages of generics?

    • Options
    • A. Generics shift the burden of type safety to the programmer rather than compiler.
    • B. Generics require use of explicit type casting.
    • C. Generics provide type safety without the overhead of multiple implementations.
    • D. Generics eliminate the possibility of run-time errors.
    • E. None of the above.
    • Discuss
    • 8. Which of the following is the correct way to implement a read only property Length in a Sample class?

    • Options
    • A.
      class Sample
      {
          int len;
          public int Length
          {
              get
              {
                  return len;
              } 
          } 
      }
    • B.
      class Sample
      {
          public int Length
          {
              get
              {
                  return Length;
              } 
          } 
      }
    • C.
      class Sample
      {
          int len;
          public int Length
          {
              get
              {
                  return len;
              } 
              set
              {
                  len = value;
              } 
          } 
      }
    • D.
      class Sample
      {
          int len;
          public int Length
          {
              Readonly get
              {
                  return len;
              } 
          } 
      }
    • Discuss
    • 9. Which of the following are necessary for Run-time Polymorphism?

      1. The overridden base method must be virtual, abstract or override.
      2. Both the override method and the virtual method must have the same access level modifier.
      3. An override declaration can change the accessibility of the virtual method.
      4. An abstract inherited property cannot be overridden in a derived class.
      5. An abstract method is implicitly a virtual method.

    • Options
    • A. 1, 3
    • B. 1, 2, 5
    • C. 2, 3, 4
    • D. 4 only
    • Discuss
    • 10. If s1 and s2 are references to two strings then which of the following are the correct ways to find whether the contents of the two strings are equal?

      1. if(s1 = s2)
      2. if(s1 == s2)
      3. int c;
        c = s1.CompareTo(s2);
      4. if( strcmp(s1, s2) )
      5. if (s1 is s2)

    • Options
    • A. 1, 2
    • B. 2, 3
    • C. 4, 5
    • D. 3, 5
    • Discuss


    Comments

    There are no comments.

Enter a new Comment