Home > Articles

Classes and Objects

  • Print
  • + Share This
This chapter is from the book

Object Operators

Now it's time to introduce some more operators that are used with classes. I've already introduced New. Two others are Isa and Is.

Isa is used to determine whether an object belongs to a class:

Dim t,u as Boolean
t = (a Isa Alpha) // t is True
u = (b Isa Alpha) // u is True
t = (a Isa Beta) // t is False
u = (b Isa Beta) // u is True

This is an example of the most basic feature of inheritance. A subclass is a member of the superclass, but the superclass is not a member of the subclass.

The related Is operator tests to see if one object is the same object as another one.

Dim t as Boolean
t = (a Is b) // t is False

Note that even though a and b both have the same values, they are different objects because they were both instantiated independently. Here's an example of when this test would return True:

Dim a,b as Alpha
Dim t as Boolean
a = new Alpha("Woohoo!")
b = a
t = (a is b) // t is True

Because b is a reference to a, it is considered the same object. In other words, both a and b point to the same location in memory. They do not simply share an equivalent value; they are, in fact, the very same object.

  • + Share This
  • 🔖 Save To Your Account