10.6. Chapter Review

  • Follow the lab assignment format to prepare this assignment.

  • Create a project folder called Ch10Classes to include the code for this project.

  • Question 6~10 require code and execution screenshots when applicable.

  1. What is the keyword used to create an instance of a class?

  2. Can you create an object from a class resides in another file?

  3. What is the purpose of a constructor?

  4. Describe the process of implementing inheritance in polymorphism in steps.

  5. If you want to use an instance variable (field) in a method, should you declare that instance variable in the method? Why?

  6. How do you create an instance of the following class?

    class DoMath
    {
        public int Sum(int num1, int num2)
        {
            var total = num1 + num2;
            return total;
        }
    }
    
  7. How do you use the following class to use the Sum method for summing up two integers? Prepare your code in your Program.cs Main method.

    static class SomeMath
    {
        public static int Sum(int a, int b)
        {
            return a + b;
        }
    }
    
  8. Define a Math class, when instantiated, offer the functionality of two summing methods with the same name Sum that would take 2 and 3 arguments, respectively, and sum them up and return the results.

  9. Change the preceding code to allow the passing of an unspecified number of integer arguments (see, e.g., https://stackoverflow.com/questions/1996426/pass-multiple-optional-parameters-to-a-c-sharp-function). Save the file in the project folder,call it SumManyArgs.cs and use SumManyArgs as the class name.

  10. Does the following code define a public or private class? Add an access modifier without changing the existing accessibility level. Show your changed code and explain why.

    class Customer
    {
        // Fields, properties, methods and events go here...
    }