Inheritance & Polymorphism in VB.Net
If you are new to VB.Net SchoolThis is the 5th in the series of lessons of our VB.Net School. The VB.Net School is a kind of interactive learning platform where those who want to learn .NET with VB.Net can find help and support. With one issue a week, describing some areas of the VB.Net Programming Language with the Microsoft .Net Platform, this is not the same traditional passive tutorial where the author only writes and the reader only reads. There will be exercise problems at the end of each issue, which the reader is expected to solve after reading the issue. The solution to these problems will be provided in the next issue for testing purposes. There is also a dedicated message board attached with the school, where you can ask questions about the article, and the author will respond to your question within 2/3 days. You can send your suggestions, feedback or ideas on how these lessons can be improved to either the Author ( farazrasheed@acm.org) or the WEBMASTER ( info@programmersheaven.com). For previous lessons click here
Lesson Plan
We will learn the fundamental object oriented features such as inheritance and polymorphism in VB.Net. We will start with building some understanding of inheritance and then will move towards understanding how VB.Net supports inheritance. We will spend some time exploring the Object class and then we will head towards polymorphism and how polymorphism is implemented within VB.Net. We will close this session with the understanding of boxing, un-boxing and how the type-casting mechanism works in VB.Net
Inheritance
Unless this is your first brush with object oriented programming, you will have heard a lot about Reusability and Extensibility. Reusability is the property of a module (a component, class or even a method) that enables it to be used in different applications without any or little change in its source code. Extensibility of a module is it's potential to be extended (enhanced) as new needs evolve. Reusability in Object Oriented Programming languages is achieved by reducing coupling between different classes while extensibility is achieved by sub-classing. The process of sub-classing a class to extend its functionality is called Inheritance or sub-typing.
The original class (or the class that is sub-typed) is called the base, parent or super class. While the class that inherits the functionality of base class and extends it in its own way is called a sub, child, derived or an inherited class.

In the figure above, we have used a UML's (Unified Modeling Language) class diagram to show Inheritance. Here, Shape is the base class while Circle, Rectangle and Curve are its sub-classes.
The Base class usually contains general functionality while the sub-classes possess specific functionality. So, when sub-classing or inheriting, we go 'from specialization to generalization'.
If class B (sub class) inherits class A (base class), then B would have a copy of all the instance members (fields, methods, properties) of class A, and B can access all the members (except for private members) of class A. Private members of the base class do get inherited in the sub-class but they can not be accessed by the sub-class. Also, inheritance is said to create a 'type of' relationship among classes which means sub-classes are a type of base class. (If this is not clear, don't worry, things will get more clear when we look at implementing inheritance in the following sections)
Inheritance in VB.Net
Before we go on to implementation, here are some key-points regarding inheritance in VB.Net
- VB.Net, like C#, Java and contrary to C++, allows only single class inheritance. Multiple inheritance of classes is not allowed in VB.Net
- The Object class defined in the System namespace is implicitly the ultimate base class of all the classes in VB.Net (and the .Net framework)
- Interfaces, in VB.Net, can inherit more than one interface. So, multiple inheritance of interfaces is allowed in VB.Net (again similar to C# and Java). We will see interfaces in detail in the coming lessons
- Structures in VB.Net, can only inherit (or implement) interfaces and can not be inherited.
School Home
|
|
Anonymous
(Report as abusive) |
very sofisticste the subject is not easy , but well explained . i sugest more examples . |
|
david
(Not rated) From israel (Report as abusive) |
what do you meen by that Reusability in Object Oriented Programming languages is achieved by reducing coupling between different classes while extensibility is achieved by sub-classing. this sentence look very important but very dificult to understend .can you detail more ? |
|
Mohit
(Report as abusive) |
Amazing Gr8 Work. Very good tutorial for the beginners in very good understanding form. Many Thanks. |
| View all Rate and comment this article |
Sponsored links
Check For Updates
Easily add update features to your applications. A complete .Net updating solution.
Easily add update features to your applications. A complete .Net updating solution.
Build IT Knowledge with Current & Trusted Content
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Helps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.
Check Out IT Certification Preparation Materials
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Sign Up With SkillSoft & Get Access to Training Materials for Over 50 Professional Certifications.
Online Crash Analysis
Automatically capture customer crash data, no debugger required. Support for .NET, C++, OS X, Java.
Automatically capture customer crash data, no debugger required. Support for .NET, C++, OS X, Java.
.Net Localization Tool Sisulizer
Localize your .Net apps: ResX and assemblies. Database, XML & HTML Help localization. Try Sisulizer!
Localize your .Net apps: ResX and assemblies. Database, XML & HTML Help localization. Try Sisulizer!
