Appendix

Answers to Exercises

Chapter 2

Exercise 1 Solution

A class is a body of code that contains properties and methods that describe an object. An object is an instance of a class that can be used in a program. Classes and objects are related in that a class is a template from which an object is created. They are different in that a class is not directly used in a program, whereas an object is.

Exercise 2 Solution

The Five Program Steps:

  • The Initialization step creates the environment in which the program is run.
  • The Input step is responsible for collecting all the information necessary for the program to accomplish its given task.
  • The Process step takes the data and acts on it in a way that accomplishes a given task.
  • The Output step presents the results of the Process step in a way that is useful to the user.
  • The Termination step is responsible for placing the program environment back to the state that prevailed before the program was run, updating any environment information that might be used the next time the program is run.

Exercise 3 Solution

The first statement defines a reference variable that you can use to access a clsThingie object. The second statement instantiates a clsThingie object and makes its properties and methods available through the reference variable named myThingie.

Exercise 4 Solution

A simple oven might have the following properties and methods:

// ================ Properties =================== int ovenTemp; // 0 is off, otherwise desired temperature ...

Get Beginning Object-Oriented Programming with C# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.