![]() ![]() | ||
As mentioned earlier, we took a look at overloading methods and properties in Chapter 11; however, there's more to this subject when inheritance enters the picture. You can use the Overloads keyword to indicate that you're overloading a method or property; that keyword isn't necessary when you're overloading a method or property in the same class, but it is when you're overloading a method or property from another class, such as a base class. In that case, you must use the Overloads keyword, as in this example, where I'm overloading the Animal class's Breathe method, which takes no arguments, in the Fish class, creating a version that you can pass text to:
Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click jaws = New Fish(Me) jaws.Breathing("Bubbling...") End Sub Public Class Fish Inherits Animal Public Sub New(ByVal form1 As Form1) MyBase.New(form1) End Sub Public Overloads Sub Breathing(ByVal Text As String) MyBase.MainForm.TextBox1.Text = Text End Sub End Class
Related solution: |
Found on page: |
---|---|
513 |
![]() ![]() | ||