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: |
|
7: |
|
8: | The following line creates a new Cat object. What do the parentheses after Cat signify? Cat myCat = new Cat(); |
9: | How can overloaded constructors make a class more flexible to use? |
10: | Why would you ever want a constructor that cannot be called from outside its class? How do you declare this kind of constructor? What is it called? |
11: | When is a static constructor called?
|
12: | Could you design a program that allows the end user to assign a value to a:
Hint: What is the lifetime of a constant member? What is the lifetime of a readonly instance member? |
13: | Briefly explain what it means for an object to be out of reach. |
14: | What are the two main tasks of the garbage collector? |
15: | Why does the garbage collector not just garbage collect any object that goes out of reach immediately? |
16: | What is a destructor? Why is it not useful for freeing up scarce non-memory resources? |
17: | A program contains a class called Book that contains 10 instance variables all of a simple type. During the execution of the program, 50 Book objects are created and most of them are destroyed. Is the garbage collector likely to run during the execution of your code? |
18: | Why should you be careful when using C# (at this time of writing) for real time applications? |
19: | Briefly explain why it is a good idea to use the Dispose design pattern to free scarce non-memory resources. |