Review Questions


In one sentence , define polymorphism.


Polymorphism is the ability to have different classes implement a common interface in different ways. An important concept behind polymorphism is that each class can respond to a given message in different ways.


Why does Visual Basic .NET allow multiple constructors for a class?


By allowing multiple constructors, Visual Basic .NET lets you create an object with default values or more specific values. Normally, instantiating an object without passing any arguments to the constructor results in creating the object with a set of default values for the member data. A second contructor must pass at least one argument (so the signatures are different) and allows the programmer to create the object with a different set of values for the member data.


What information does the following statement tell you?

 Public MustOverride Function RentalRooms() As Integer 

This statement tells you a number of things. First, because the MustOverride keyword appears in the declaration, the class in which the statement appears is serving as a base class for some other class. Second, the MustOverride also tells you that the statement is a signature declaration. This means no lvalue exists for RentalRooms() at this point in the code. Third, the MustOverride also tells you that all derived classes must write the code for the function named RentalRooms(). Finally, the statement tells you exactly how the signature for the function must be written in the derived classes. If you try to write the function using a different name , argument list, or return value, Visual Basic .NET will issue an error message.


How would you define a virtual class named Golfer ?


When you begin the class definition, you would use:

 Public MustInherit Class Golfer 

The MustInherit keyword tells Visual Basic .NET that this class is a virtual class.


What do the following statements mean?

 Interface IKeepScores  Function PostScore() As Integer End Interface 

The statements mean that an interface is being declared. The IKeepScores interface requires that any programmer using the interface must write code for the function named PostScore() using the signature shown in the Interface statement body. If needed, the interface can have multiple procedures as part of the interface declaration.


If an interface is declared in the manner suggested in question 5, what statement is needed to use the interface in your code?


The class that wishes to implement the interface must place the following statement in the class:

 Implements IKeepScores 

This statement has the effect of creating a contract between you and Visual Basic .NET. You are promising to implement the code for the procedure(s) that are associated with the IKeepScores interface. If you fail to implement every procedure in the IKeepScores interface, Visual Basic .NET will tell you that you are breaking your contract.


Given the answers to questions 5 and 6, write the signature for the PostScore() function.


The signature must be written:

 Public Function PostScore() As Integer Implements IKeepScores.PostScore 

The only difference between writing an interface function and any other function is that you must append the Implements keyword, followed by the interface name, the dot operator, and then the function name. You can then write the code for the function as you would write code for any other function.

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

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: