Prev | Current Page 85 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

DoSomething().We do this by calling the A.DoSomething() implementation
directly from within B.DoSomething(), using the MyBase keyword.
MyClass is like an object variable that always refers to the current instance of a class as it
was implemented. The MyClass keyword executes its call as if the method or property had been
marked NotOverridable. The following code demonstrates:
Public Class A
Private x As Integer
CHAPTER 3 n CLASSES AND STRUCTURES 40
Public Sub New(ByVal var As Integer)
Me.x = var
End Sub
Public Overridable Sub DoSomething()
System.Console.WriteLine("A.DoSomething")
End Sub
Public Sub UseMe()
Me.DoSomething()
End Sub
Public Sub UseMyClass()
MyClass.DoSomething()
End Sub
End Class
Public Class B
Inherits A
Public Sub New()
MyBase.New(123)
End Sub
Public Overloads Overrides Sub DoSomething()
System.Console.WriteLine("B.DoSomething")
MyBase.DoSomething()
End Sub
End Class
Public Class EntryPoint
Shared Sub Main()
Dim b As B = New B()
b.UseMe()
b.UseMyClass()
End Sub
End Class
Here??™s the output from the preceding code:
B.DoSomething
A.DoSomething
A.DoSomething
The b.UseMyClass method call executes the A.DoSomething method. This is because even
though the UseMyClass method is called from an instance of Class B, the method uses the
CHAPTER 3 n CLASSES AND STRUCTURES 41
MyClass keyword, causing it to call the DoSomething method in Class A.


Pages:
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
trener nlp ceny żywca leczenie alkoholizmu Kołobrzeg aquilamed