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

Working with classes (object orientation)

This lesson covers the basics of object-oriented programming with VB.NET's Class syntax, with the aim of handling data that shares a common nature.

Class ... End Class defines a class, and New is the special procedure used to initialise it. The class is the blueprint and the thing built from it is the instance — a way of modelling real things in a program.

The sample code gives an Animal class Name and Sound properties and assembles the sound message in a Speak() function. Note the call to dog.Speak() on the instance created with New Animal("Dog", "Woof").

A common early stumble is the Me keyword. Reaching your own property from inside the class means writing Me.Name, and missing that is confusing.

Gathering fields (data) and methods (behaviour) into one thing is the great benefit of a class. Object orientation lets you express real-world things in a program more naturally.

๐Ÿ“– 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)