Warm-up Exercises

Questions

  1. Explain why variables are private and methods are public in object oriented languages.

    Solution

    Variables are kept private to prevent their modification by external code or programs. Methods are left public because they are designated to allow external code or programs to interact with the contents of a class or object.

Explain the difference between public property and public auto-implemented property.

Solution

Public properties are used to access private variables similarly to Get and Set methods and may contain logic to check values being assigned or returned. Auto-implemented properties are those which do no more than store and return values.  
  1. What, if any, is the difference between a parameter and an argument?

Solution

A parameter is the placeholder for an argument in a method definition, and an argument is the actual value passed into a method call.

Problems