Home > Articles > Programming > .NET and Windows Programming

Inheritance and Polymorphism in VB.NET

Paul Kimmel
  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close WindowPaul Kimmel

Paul Kimmel

Learn more…

Debugging Client-Side JavaScript for ASP.NET with Visual Studio
Sep 16, 2009
Using Entity SQL As Your Data Access Layer
Dec 2, 2008
Programming with LINQ to XML for Objects
Nov 21, 2008
Bill Wagner on C#, LINQ, and Writing Books
Oct 6, 2008
Writing LINQ Queries with the Entity Framework
Sep 23, 2008
Using Parallel LINQ
Aug 15, 2008
Programming with Anonymous Types in C#
Aug 11, 2008
Querying SQL with LINQ
Jul 28, 2008
Writing Lambda Expressions in the .NET Framework
Jun 11, 2008
Programming with Generic Delegates in .NET
May 8, 2008
Managing Database Transactions with the TransactionScope
Sep 7, 2007
Letting ADO.NET Write Your SQL
Jun 8, 2007
Using C#'s yield to Return an Enumerable Collection
Apr 27, 2007
Using the My Feature in Visual Basic .NET
Sep 8, 2006
Programming with the BackgroundWorker Component in .NET 2.0
Apr 7, 2006
How to Use Partial Classes in Visual Studio 2005
Jan 13, 2006
Generic Classes in C# 2.0
Nov 11, 2005
Anonymous Methods in C# 2.0
Oct 28, 2005
Implementing an XML Section Handler in .NET
Sep 16, 2005
.NET Remoting: Handling Remote Server Events
Feb 11, 2005
Converting XML Nodes into Objects
Dec 10, 2004
Using Application Blocks for Data Access
Oct 22, 2004
A Roll of the Dice: Building a Small Game Using Windows Graphics Programming
Oct 1, 2004
Through the Looking Glass: Debugging Hosted .NET Applications
May 13, 2004
Listening to Trace Messages in NUnit
May 7, 2004
Instrumenting Your Code for Exception Management
Dec 23, 2003
What's .NET Remoting, And Why Should You Care?
Dec 12, 2003
Injecting Dynamic JavaScript to Focus ASP.NET Controls
Oct 10, 2003
Defining Add and Remove Accessor Methods for Events in VB.NET
Apr 18, 2003
Debugging .NET with NUnit
Mar 14, 2003
Dynamic Debug Code Management with BooleanSwitches
Feb 28, 2003
Creating Typed DataSets with XML Schemas
Jan 24, 2003
Fall Comdex 2002: .NET or .What?
Jan 10, 2003
Managing Session State for ASP.NET
Nov 15, 2002
Creating Project Templates in .NET
Oct 25, 2002
Creating Custom Attributes in Visual Basic .NET
Oct 11, 2002
Asynchronous Web Services
Sep 20, 2002
Inheritance and Polymorphism in VB.NET
Aug 9, 2002
Serializing Objects to a .NET DataSet
Jul 19, 2002
Implementing the Strongly Typed Collection in C#
Jul 5, 2002
Emitting MSIL with Reflection
Jun 28, 2002
Programming with Regular Expressions in C#
Jun 21, 2002
Creating Data-Enabled Web Pages using the DataList
Mar 8, 2002
Creating Visual Studio .NET Add-Ins
Mar 8, 2002
Lightweight Threading with Thread Pools in Visual Basic .NET
Mar 8, 2002
Understanding Delegates in Visual Basic .NET
Mar 8, 2002
Working with New Abstract Data Types in Visual Basic .NET
Mar 8, 2002
Storing Your Access Data
Feb 8, 2002
Adding Data to Web Pages
May 11, 2001

Sorry, this author hasn't posted any blogs.

Visual Basic .NET Unleashed

This chapter is from the book
Visual Basic .NET Unleashed

Harness the added power of VB.NET's inheritance capabilities by exploring subclassing, polymorphism, dynamic typecasting, and interface definitions.

In This Chapter

  • Inheritance Basics
  • What Is Inheritance?
  • Defining Classes That Must Be Subclassed
  • Defining Classes That Cannot Be Subclassed
  • Polymorphism
  • Dynamic Typecasting
  • Defining Interfaces
  • Summary

Visual Basic .NET supports inheritance. VB6 did not. VB6 supported interface implementation, which is a facility of the Component Object Model (COM). Why Microsoft chose to implement COM and interfaces before classes and inheritance is anybody's guess, but Visual Basic .NET supports both interfaces and inheritance. The net result is that Visual Basic .NET is significantly more powerful and has features and capabilities consistent with the most advanced languages available today.

Through version 6, we said that Visual Basic was object-based rather than object- oriented. The primary missing ingredient was inheritance. Visual Basic .NET rectifies this deficit.

Chapter 10 demonstrates how to use inheritance in Visual Basic .NET, as well as the new capabilities associated with inheritance relationships. Additionally there are revisions to the way interfaces are supported in Visual Basic .NET. Chapter 10 will demonstrate inheritance, virtual abstract classes, final classes, polymorphic behavior, dynamic typecasting, and how to define and implement interfaces in Visual Basic .NET.

Inheritance Basics

Interfaces contain declarations only. Classes can contain both declarations and definitions. Classes can implement interfaces as well as inherit from a single parent class. Interfaces use the keyword Interface, and classes use the keyword Class in Visual Basic .NET.

The difference between an interface and a class is that classes provide implementations for their members and interfaces define members without implementations. Both classes and interfaces support inheritance. A class may inherit from a single parent and implement zero or more interfaces, and interfaces support multiple interface inheritance but provide no implementation. (We will return to interfaces later in this chapter. For now let's focus on what classes offer.) Even if your understanding of inheritance is expert, you are encouraged to read the remainder of this section simply to see the grammar used to support class inheritance in Visual Basic .NET.

  • Share ThisShare This
  • Your Account

Discussions

A Problem
Posted Jul 4, 2008 03:34 PM by vkvikas50
0 Replies
A Problem
Posted Jul 4, 2008 03:33 PM by vkvikas50
0 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on November 19, 2009 No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network