Two Different Kinds of 'Many Forms'
Overloading and overriding both let a member share a name across multiple definitions, but they solve different problems. Overloading defines several methods with the same name but different parameter lists within the same class, resolved at compile time based on the arguments you pass. Overriding, by contrast, happens across a class hierarchy: a derived class replaces the implementation of a specific Overridable member inherited from its base class, resolved at run time based on the actual object type.
Cricket analogy: A bowler having multiple deliveries all called 'yorker' but distinguished by pace and line is like overloading -- same name, different inputs, chosen at the moment of delivery -- while a young pacer redefining how the yorker is executed compared to Bumrah's version is like overriding.
Method Overloading with Overloads
In VB.NET, overloaded methods must be explicitly marked with the Overloads keyword when Option Strict is on, and each version must differ in the number, order, or type of its parameters -- return type alone is not enough to distinguish them. The compiler picks the correct overload by matching the arguments at the call site, so calling Format(42) invokes a different method body than calling Format("hello").
Cricket analogy: A stadium PA announcer having distinct scripted lines for Wicket(bowlerName) versus Wicket(bowlerName, dismissalType) is like overloaded methods -- the correct script is chosen automatically based on which information is supplied.
Public Class Formatter
Public Overloads Function Format(value As Integer) As String
Return "Integer: " & value.ToString("N0")
End Function
Public Overloads Function Format(value As String) As String
Return "Text: " & value.ToUpper()
End Function
Public Overloads Function Format(value As Double, decimals As Integer) As String
Return "Double: " & value.ToString("F" & decimals)
End Function
End Class
Dim f As New Formatter()
Console.WriteLine(f.Format(1500)) ' Integer: 1,500
Console.WriteLine(f.Format("hello")) ' Text: HELLO
Console.WriteLine(f.Format(3.14159, 2)) ' Double: 3.14Overriding with Overridable, Overrides, and MustOverride
MustOverride takes overriding a step further: it declares a member signature in a MustInherit (abstract) base class with no body at all, forcing every concrete derived class to supply its own implementation before it can be instantiated. This differs from a merely Overridable member, which provides a usable default implementation that derived classes may replace but are not required to.
Cricket analogy: A federation's rule that every affiliated national board must define its own domestic qualification pathway, with no default provided centrally, mirrors MustOverride -- there's no fallback implementation, each board is forced to supply one.
A MustInherit class cannot be instantiated directly with New -- attempting New Shape() on a MustInherit Shape class is a compile error. Only a concrete derived class that implements every MustOverride member can be instantiated.
Operator Overloading
VB.NET also allows Operator Overloading, letting a class redefine how standard operators like +, -, or = behave when applied to its own instances, declared with Public Shared Operator +(left As T, right As T) As T inside the class. This is commonly used for value-like types such as a Money or Vector2D class, where writing point1 + point2 reads far more naturally than calling an Add() method.
Cricket analogy: Combining two batting partnerships' run totals with a simple '+' to get the team score, rather than calling a verbose AddPartnershipRuns() method, mirrors how Operator Overloading lets natural symbols express domain logic cleanly.
Operator Overloading can hurt readability if the operator's meaning isn't obvious for the type -- reserve it for genuinely value-like types like Money or Vector2D. Also remember that Option Strict On is what makes VB.NET flag ambiguous overload resolution as a compile-time error rather than a surprising runtime pick.
- Overloading defines multiple methods with the same name but different parameter lists, resolved at compile time.
- Overriding replaces a base class's Overridable implementation in a derived class, resolved at run time.
- The Overloads keyword is required to mark overloaded members when Option Strict is On.
- Overload resolution depends on argument number, order, and type -- never on return type alone.
- MustOverride declares a bodyless signature inside a MustInherit class, forcing concrete subclasses to implement it.
- Operator Overloading lets a class redefine +, -, =, and other operators for its own instances.
- Operator Overloading is best reserved for value-like types where the operator's meaning is obvious.
Practice what you learned
1. Overloading resolves which method to call based on:
2. Overriding resolves which implementation runs based on:
3. In VB.NET, what keyword must mark overloaded methods when Option Strict is On?
4. Which keyword forces every concrete derived class to supply its own implementation with no default body?
5. What does VB.NET's Operator Overloading let a class do?
Was this page helpful?
You May Also Like
Inheritance and Interfaces
Explore how VB.NET classes reuse and extend behavior through Inherits, Overridable/Overrides, and how Interfaces define implementation-free contracts.
Classes and Objects in VB.NET
Learn how VB.NET classes act as blueprints and objects as their instances, covering fields, methods, constructors, and Shared members.
Collections and Generics in VB.NET
Move beyond fixed arrays to type-safe, resizable generic collections like List(Of T) and Dictionary(Of TKey, TValue), and write your own generic methods.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics