O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required