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.

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?
3:What constructor names can you use for a class called Robot?
4:Are constructors only used to initialize instance variables?
5:What is the return type of a constructor?
6:
  1. A Dog class contains no constructor definitions in the source code. Is the following statement ...

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.