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;



num = nc(5);

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





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. When you create an abstract method, you provide __________.

4. Abstract classes and interfaces are similar in that __________.

you can instantiate concrete objects from both
you cannot instantiate concrete objects from either one
all methods in both must be abstract
neither can contain nonabstract methods

5. When you create any derived class object, __________.

the base class and derived class constructors execute simultaneously
the derived class constructor must execute first, then the base class constructor executes
the base class constructor must execute first, then the derived class constructor executes
neither the base class constructor nor the derived class constructor executes

6. In a program that declares a derived class object, you __________ assign it to a variable of its base class type.

Source link

Leave a Reply

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