1: |
|
2: | Which capitalization style is recommended for
|
3: | The following lines specify an instance variable declaration and what is meant to be a property with the task of allowing access to the instance variable speed from outside the object. However, the property definition has four problems that need to be fixed before it will work correctly. Find and fix the problems. private double speed; private int Speed() { get { return Speed; } } |
4: | What is delayed initialization? When would you use it? Could delayed initialization also be implemented with accessor and mutator methods? |
5: | The header of the following indexer declaration has three problems. What are they? static int myIndexer this [ ] { ... } |
6: | The Rainfall class contains an array with twelve elements. It also contains an indexer to access the array elements, which, like its array, is zero-based (first element is zero). A rainfallParis object is instantiated from the Rainfall class.
|
7: | You have just finished implementing your Car class and are satisfied with the end result. During a quiet moment of contentment, your colleague suddenly suggests that to make the Car class perfect, you should include operator overloading for the class so it can be used with the + and - operators and support code like car3 = car1 + car2. Is this a good idea? Why or why not? |
8: | Why is operator overloading sometimes referred to as syntactic sugar? |
9: | Recall the TimeSpan class from Listing 14.7. It already includes an operator + method to add two TimeSpan objects together and assign the result to a TimeSpan reference variable. Your colleague decides to include an operator - method so that TimeSpan objects can be subtracted. The following is the code he initially inserted into the TimeSpan class. It contains several flaws. Find them. private TimeSpan (TimeSpan timeSpan1, TimeSpan timeSpan2) { return (timeSpan1.Seconds timeSpan2.Seconds) } |
10: | Among other program elements, your program contains the two classes EarthTimeSpan and BliposTimeSpan. Each class still contains an instance variable called totalSeconds of type uint. In this case, EarthTimeSpan contains a user-defined explicit conversion to the type short, and BliposTimeSpan contains a user-defined implicit conversion from the type decimal to BliposTimeSpan. myShort is a variable of type short and myDecimal is a variable of type decimal, earthTimeSpan1 is of type EarthTimeSpan and bliposTimeSpan1 is of type BliposTimeSpan. Determine whether each of the following statements is valid:
|
11: | You are writing a program that will assist architects in drawing architectural plans. The program contains many classes that rely on manipulating two-dimensional drawings. One of these classes is called Bathroom, and it represents and manipulates drawings of bathrooms. It needs a class called Point to represent a point consisting of two coordinates. Would it be a good idea to nest this class in the Bathroom class? Why or why not? |