Chapter 13

Answers to Chapter 13 Review Questions

1: A class called Robot contains the following two instance variable declarations:
private ushort age;
private bool isConnected;

What is the value of age and isConnected immediately after their object has been instantiated?

Improve the style of the declarations without changing the semantics of the code.

A1: age has the value 0 and isConnected the value false.

Improved code would be as follows:

private ushort age = 0;
private bool isConnected = false;
2: The users of your Robot class would like to assign a value to age at the same time as they are instantiating a Robot object. How would you accommodate for this request?
A2: By equipping the Robot class with the following constructor:
 public Robot(ushort ...

Get C# Primer Plus 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.