Module Module1 Public Class Control 'These members are private and thus invisible 'to derived class methods we'll examine this 'later in the chapter Private top As Integer Private left As Integer 'Constructor takes two integers to 'fix location on the console Public Sub New(ByVal top As Integer, ByVal left As Integer) Me.top = top Me.left = left End Sub 'Simulates drawing the control Public Overridable Sub DrawControl() Console.WriteLine("Drawing Control at {0}, {1}", top, left) End Sub End Class 'TextBox derives from Control Public Class TextBox Inherits Control Private mTextBoxContents As String 'New member variable 'Constructor adds a parameter Public Sub New(ByVal top As Integer, ByVal left As Integer, ByVal theContents As String) MyBase.New(top, left) ' call base constructor mTextBoxContents = theContents End Sub 'A new version (note keyword) because in the 'Derived method we change the behavior Public Overrides Sub DrawControl() MyBase.DrawControl() 'Invoke the base method Console.WriteLine("Writing string to the textbox: {0}", mTextBoxContents) End Sub End Class Sub Main() 'Create a base instance Dim contr As Control = New Control(5, 10) contr.DrawControl() 'Create a derived instance Dim txt As TextBox = New TextBox(20, 30, "Hello world") txt.DrawControl() Console.ReadLine() End Sub End Module