Interview Tips Interview Tips, Interview Questions and Answers

12Dec/100

What is a good exception?

1. throwing an exception when an invalid parameter is passed to a method. The ArgumentException or one of its derived exception classes should be thrown in this situation.
2. throwing an exception when a call is made to a method that cannot operate because other information must be initialised or other methods must be called beforehand. An InvalidOperationException could be thrown in this case.

6Jan/100

.Net Interview: Method and Property Questions

    1. What does the keyword “virtual” declare for a method or property?
      The method or property can be overridden.
    2. What’s the implicit name of the parameter that gets passed into the set method/property of a class?
      Value. The data type of the value parameter is defined by whatever data type the property is declared as.
    3. How is method overriding different from method overloading?
      When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.
    4. What are the different ways a method can be overloaded?
      Different parameter data types, different number of parameters, different order of parameters.
    5. If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?
      Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.
    6. Can you declare an override method to be static if the original method is not static?
      No. The signature of the virtual method must remain the same.  (Note: Only the keyword virtual is changed to keyword override)