Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 16 / 68

Inheritance (extending a class)

This lesson covers extending a class through inheritance in VB.NET, with the aim of reusing code across classes that share a nature.

Inherits creates a new class carrying the nature of an existing one. Inheritance lets you gather the shared work into a parent class and write only the differences in each child.

The sample code makes Dog inherit the parent Animal with Inherits Animal. A parent function marked Overridable is replaced in the child with Overrides, changing only the sound message.

A common early stumble is that overriding needs the Overridable and Overrides pair. Forget Overridable on the parent and the child cannot override it, which is a compile error.

In professional work, inheritance is used wherever several classes share a nature — kinds of animal, kinds of shape. Gathering the common part into a parent reduces duplication.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)