| 1: || |
In one sentence , what is the major purpose of encapsulation as it relates to OOP?
| A1: || |
The major purpose of encapsulation is that it hides the data members and the methods that operate on that data within the object itself, thus reducing the possibility of data contamination.
| 2: || |
What is the difference between a class member and a class method?
| A2: || |
Class members are like nouns in a sentence. A class member is a property of the class and is normally used to describe the state of the object.
Class methods are like verbs in a sentence. A class method is a procedure that is used to retrieve or set a class member's data.
| 3: || |
What does the term overloaded mean in OOP?
| A3: || |
OOP allows a procedure to have multiple class methods that share the same name . If a method does have more than one definition in the current scope, it is called an overloaded method.
| 4: || |
What is meant by the term signature in OOP?
| A4: || |
The term signature refers to the components of a statement that define the procedure. For example,
Public Function MyFunction(arg1 as Integer) as Integer
describes the signature for the method named MyFunction() . Every procedure and method in a Visual Basic .NET program must have a unique signature. If this condition is violated, a "duplicate definition" error is generated.
| 5: || |
If a method is overloaded, how does Visual Basic .NET know which method to use?
| A5: || |
In order to have an overloaded method, each method must share the same name, but have different argument lists and/or return lists. In other words, the signatures for the functions must be different. For example,
Public Function MyFunction() as Integer ' The code for the function Public Function MyFunction(arg1 as Integer) as Integer ' The code for the function
illustrates that MyFunction() is overloaded because they share the same name, but have different signatures.
| 6: || |
What is a class Helper procedure?
| A6: || |
A Helper procedure is a procedure that is designed to accomplish a specific task for the class, but is not to be called from outside the class. Because Helper procedures are to be used only within the class itself, the access specifier for Helper procedures should be Private . The Private access specifier assures that the procedure is not available outside the class.
| 7: || |
Suppose you are writing a class named Golfers that describe a person who plays golf. You create an Integer data member named mHandicap that records the player's handicap. Write the property methods necessary to set and retrieve a player's handicap.
| A7: || |
The methods could be written as follows :
Property Handicap() As Integer Get Return mHandicap End Get Set(ByVal Value As Integer) mHandicap = Value End Set End Property
Usually, properties are written in pairs to allow the property to be set or retrieved.
| 8: || |
Using your answer to question number 7, what would the statement look like to set a player's handicap to 36? To retrieve it?
| A8: || |
The following is an example:
Dim JohnMarsh As New Golfers Dim Handicap As Integer Handicap = 36 JohnMarsh.Handicap = Handicap ' Set it Handicap = JohnMarsh.Handicap ' Get it
| 9: || |
Given your answer to question number 8 and that the Get and Set methods use the same property name, how does Visual Basic .NET know which method to use?
| A9: || |
This is one case where the context determines which property method is used. If the property method appears on the left-hand side of an assignment operator, Visual Basic .NET knows that a Set operation is being performed. If the property method appears on the right side of an assignment operator, Visual Basic .NET knows that a Get operation is being performed. Even though the same keywords and variables are used in both statements, their context is very different.