Review Questions


Programmer's Tip

graphics/tip_icon.gif

Students hate questions that begin with "In one sentence " I believe the reason is because it limits their ability to engage in elocutionary effervescence. Although some topics simply cannot be reduced to a single sentence, those topics are fairly rare. In all other situations, if you cannot define something clearly in a relatively short sentence , you probably don't understand it completely. Also, communicating effectively in relatively few words is an important springboard to corporate advancement. After all, as a manager, would you rather get the same information from a 1-page report or a 14-page report?


1:

In one sentence, define what inheritance brings to the programmer's table.

A1:

Inheritance provides the ability to absorb all the functionality of an existing class as the starting point for the development of a new class.

2:

How does a derived class relate to a base class?

A2:

A base class serves as a collection point for the properties and methods that are expected to be shared in common with a derived class. A derived class adds to the base class properties and methods whatever additional properties and methods are necessary to completely describe the derived class object. In other words, the base class becomes the common denominator for all derived classes.

3:

How does the Protected access specifier differ from the Private access specifier?

A3:

The Protected access specifier indicates that any data item that has this access level is available to any member of the class, including any derived classes. If the Private access specifier is used, only the class in which the item is defined has access to the data item.

4:

How do you tell Visual Basic .NET that you want the class you are developing to use the functionality of some other class?

A4:

You use the word Inherits in the class that is assuming the existing class's functionality. These statements:

 Public Class TownHouse   Inherits Building 

say that the class being developed (that is, TownHouse ) inherits all the functionality of the Building class.

5:

Is it true that a derived class inherits all the functionality of the base class?

A5:

Not necessarily . By using different access specifiers, you can limit the functionality of derived classes.

6:

In one sentence, explain how you can distinguish a function call from a class method call in a program's code.

A6:

A class method call is prefixed with an object name and a dot operator, whereas a function call is not. (That's the one-sentence answer.) For example, in this statement:

 ThisPlayersHandicap = Players.Handicap(WhichPlayer) 

Handicap() must be a class method call because it is prefixed with an object name and the dot operator. On the other hand, this statement:

 ThisPlayersHandicap = Handicap(WhichPlayer) 

calls a function named Handicap() .

7:

Suppose an array named DaysInTheMonths() holds the number of days in a month, starting with January, and you want to copy those values into a combo box name cmbDaysInTheMonth . How would you write the code to do this? (You are only interested in the days in the month as held in the array, not the names of the months. You can also assume that element 1 in the array is January.)

A7:

The following code provides one way:

 Dim i As Integer  For i = 1 To 12  cmbDaysInTheMonth.Items.Add(DaysInTheMonths(i)) Next 
8:

What is a virtual class?

A8:

A virtual class is a class from which you expect no objects to be created directly. The only purpose of a virtual class is to collect all the common properties and methods that the derived classes will share. The virtual class is the common denominator for the derived classes, but it might not have enough detail in and of itself to be useful.

9:

What is the purpose of the Overridable keyword?

A9:

The Overridable keyword means that the base class provides a certain method, but the derived classes can implement their own methods by using the same name. If a derived class does write a replacement for the Overridable method, it must use the Overrides keyword in the definition of the method. Visual Basic .NET always uses the method of the derived class by default in such cases.

10:

How is MustOverride different from Overridable ?

A10:

MustOverride means that the derived classes must write code for the MustOverride keyword. Whereas Overridable gives the programmer the option of writing a replacement, MustOverride does not give the programmer a choice; the programmer must write the code for the MustOverride keyword. Indeed, the base class does not provide code for the MustOverride keyword.

11:

How is the Friend access specifier used?

A11:

You use the Friend access specifier when you want to make a data item accessible to an entire assembly. Friend is one step toward Public , and it's a clear step away from Private in terms of encapsulation. A common use of Friend is when you want to make a data item available to all components compiled on a Web server but hide it from all clients .

12:

Give an example of where you might use the MyBase keyword.

A12:

Suppose the base class has an Overridable method, and you are writing code for a derived class. However, instead of using the method in the class you are writing, you have one situation where you want to use the base class implementation of the method. If the overridden method is named CalcTax() , you could write this statement:

 ThisTax = MyBase.CalcTax() 

and your code would call the CalcTax() method in the base class rather than the (default) CalcTax() method you wrote for the derived class.

13:

What is the purpose of the NotInheritable keyword?

A13:

The NotInheritable keyword means the current class is the last link in the chain of derived classes. If you write a class using the NotInheritable keyword, no further classes can be derived from the class.



Visual Basic .NET. Primer Plus
Visual Basic .NET Primer Plus
ISBN: 0672324857
EAN: 2147483647
Year: 2003
Pages: 238
Authors: Jack Purdum

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net