Classes are vital aspects of OOP. A class is like the "blueprint" of an object. An object has the properties of a class, but the characteristics are not defined within the class itself. As each object can be different, they define their own characteristics.
A class can also contain subclasses. A subclass inherits the same properties and behaviors as its parent class, but can have its own unique properties and classes.
Inheritance Modifiers (on classes)
Specifies the base (or parent) class
Prevents programmers from using the class as a base class.
Specifies that the class is intended for use as a base class only. (Abstract class)
Inheritance Modifiers (on properties and methods)
Allows a property or method in a class to be overridden in a derived class.
Overrides an Overridable property or method defined in the base class.
Prevents a property or method from being overridden in an inheriting class. Default behaviour. Can only be declared on overrides methods
Requires that a derived class override the property or method.
MustOverride methods must be declared in MustInherit classes.
Me vs MyClass
Me uses the current object instance.
MyClass uses the memberdefinition in the class where the member is called
The MyBase keyword behaves like an object variable that refers to the base class of the current instance of a class.
Overloading is the creation of more than one procedure, instance constructor, or property in a class with the same name but different argument types.
It redeclares a member that is not overridable. Only calls to the instance will be affected. Code inside the base classes will not be affected by this.
Example1, Creating a new object through a generic. Which function will be used??
Output: By intuition the result should be the same. Yet that is not true.
Output: By intuition you could think that p and s are equal and will behave equal. Yet that is not true.
In this simple examples it is easy to learn the strange behaviour of Shadows. But in real-life it brings a lot of surprises. It is advisably to prevent the usage of shadows. One should use other alternatives as much as possible (overrides etc..)
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0