| 1: || |
In one sentence , define polymorphism.
| A1: || |
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.
| 2: || |
Why does Visual Basic .NET allow multiple constructors for a class?
| A2: || |
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.
| 3: || |
What information does the following statement tell you?
Public MustOverride Function RentalRooms() As Integer
| A3: || |
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.
| 4: || |
How would you define a virtual class named Golfer ?
| A4: || |
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.
| 5: || |
What do the following statements mean?
Interface IKeepScores Function PostScore() As Integer End Interface
| A5: || |
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.
| 6: || |
If an interface is declared in the manner suggested in question 5, what statement is needed to use the interface in your code?
| A6: || |
The class that wishes to implement the interface must place the following statement in the class:
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.
| 7: || |
Given the answers to questions 5 and 6, write the signature for the PostScore() function.
| A7: || |
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.