Constructors’ Inheritance
The previous section discussed the MyBase
keyword and how it can be used to access members from a base class. The keyword also has another important purpose when it comes to constructors. Consider the following constructor, which is implemented within the Person
class (that is, the base class) shown in the previous section:
Public Sub New(firstName As String, lastName As String, age As Integer) Me.FirstName = firstName Me.LastName = lastName Me.Age = ageEnd Sub
The problem now is in derived classes. The rule is that if you have a constructor receiving arguments in the base class, you do need to provide a constructor receiving arguments also within a ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.