![]() ![]() | ||
When you make a member of a class public, there are no restrictions on its scope; it can be used by any part of your program. Public members in a base class become public members of a derived class by default. You make classes and members public with the Public keyword (see "Access Modifiers" in the In Depth section of this chapter), as I've done many places in the Inheritance example on the CD-ROM, also discussed in the In Depth section of this chapter:
Public Class Form1 Inherits System.Windows.Forms.Form 'Windows Form Designer generated code Dim spot As Dog Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click spot = New Dog(Me) spot.Breathing() End Sub End Class Public Class Animal Protected MainForm As Form1 Public Sub New(ByVal form1 As Form1) MainForm = form1 End Sub Public Sub Breathing() MainForm.TextBox1.Text = "Breathing..." End Sub End Class Public Class Dog Inherits Animal Public Sub New(ByVal form1 As Form1) MyBase.New(form1) End Sub Public Sub Barking() MainForm.TextBox1.Text = "Barking..." End Sub End Class
![]() ![]() | ||