1. Output of the following code is:

delegate int NumberChanger(int n);

namespace DelegateApp

{

   class TestDelegate

   {

      static int num = 10;

      public static int AddNum(int p)

      {

         num += p;

         return num;

      }

      public static int MultNum(int q)

      {

         num *= q;

         return num;

      }

      static void Main(string[] args)

      {

         //create delegate instances

         NumberChanger nc;

         NumberChanger nc1 = new NumberChanger(AddNum);

         NumberChanger nc2 = new NumberChanger(MultNum);

         nc = nc1;

         nc = nc2;

        

         //Invoke

num = nc(5);

         Console.WriteLine(“Value of Num: {0}”, num);

         Console.ReadKey();

      }

   }

}

2. What modifier should be used with a method if you have a class which can be used directly, but for which you want inheritors to be able to change certain behavior.

3. Which keyword is used to prevent a class from being inherited?

4. Which of the following is TRUE in C#?

In subclass, user can add new fields as well as deleting fields from superclass.
Methods declared as abstract don’t have method body
Classes defined sealed can be inherited.
A superclass cannot have a superclass.
A base class can only be inherited once.

5. Which of the following is TRUE for an abstract class?

All methods in an abstract class must define as abstract
All methods in an abstract class cannot be implemented.
Static method cannot be defined as abstract.
Sealed keyword can be used for an abstract method.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *