Inheritance in VB.NET
In VB.NET inheritance, a class can inherit properties, methods, and events from another class, referred to as the base class or parent class. The class that inherits from the base class is called a child class. Inheritance allows you to create a hierarchy of classes, promoting code reuse and a more organized code structure.
To demonstrate inheritance in VB.NET, let’s create an example with a base class, Animal
, and two derived classes, Dog
and Cat
:
Public Class Animal Public Property Name As String Talk Public Overridable Function Talk() As String Return "animal noise" End Function End Class
The Dog
class will inherit from the Animal
class:
Public Class Dog Inherits Animal Public Property Breed As String Public Overrides Function Talk() As String ...