I.T. Discussion Community!
-Collapse +Expand
Search VB.Net Group:

-Collapse +Expand VB.Net To/From
-Collapse +Expand VB.Net Store

Prestwood eMagazine

April Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingVB.NetOOP   Print This     
  From the January 2016 Issue of Prestwood eMag
VB.Net Abstraction (MustInherit, MustOverride, Overrides)
Posted 11 years ago on 10/24/2008 and updated 2/4/2009
VB.Net Code Snippet:
 A flashcard from our VB.Net Flashcards Library
 A code snippet from our VB.Net Code Snippets Page
 Tags: VB.Net , Abstraction


General Info: Abstract Class / Abstract Member

An abstract class member is a member that is specified in a class but not implemented. Classes that inherit from the class will have to implement the abstract member. Abstract members are a technique for ensuring a common interface with descendant classes. An abstract class is a class you cannot instantiate. A pure abstract class is a class with only abstract members.

Languages Focus: Abstraction

Abstraction is supported at various levels with each language. A language could enforce abstraction at the class level (either enforcing a no-instantiation rule or a only abstract members rule), and with class members (member methods and/or properties).

VB.Net Abstraction

VB.Net supports abstract class members and abstract classes using the MustInherit and MustOverride modifiers.

An abstract class is indicated with a MustInherit modifier and is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties.

An abstract member is either a method (implicitly virtual), property, indexer, or event in an abstract class. You can add abstract members ONLY to abstract classes using the MustOverride keyword. Then you override it in a descendant class with Overrides.

Syntax Example:
Public MustInherit Class Cyborg
  Public MustOverride Sub Speak(ByVal pMessage As String)
End Class

Public Class Series600
  Inherits Cyborg

  Public Overrides Sub Speak(ByVal pMessage As String)
  End Sub
End Class

An Abstract Example

The following demonstrates the abstract method above. The following assumes a form with a button.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,_
 ByVal e As System.EventArgs) Handles Button1.Click

Dim MyKiller As New Series600

MyKiller.Speak("I am alive.")

End Sub
End Class

Public MustInherit Class Cyborg
Public MustOverride Sub Speak(ByVal pMessage As String)
Public MustOverride Sub Walk()

  'You can implement methods in an abstract class!
Public Overridable Sub Greet()
MessageBox.Show("Hello human")
End Sub
End Class
Public Class Series600
Inherits Cyborg

  Public Overrides Sub Greet()
End Sub

Public Overrides Sub Speak(ByVal pMessage As String)
End Sub

  Public Overrides Sub Walk()
'Implement walk here.
End Sub
End Class

Abstract Properties

VB.Net does support setting a property to abstract with the MustOverride keyword. A single property line with the MustOverride keyword is all that's required. In most cases, you'll probably also want to...

Time To Sign In

You must sign in to read the rest of this document.

Not a member? Join now! Membership is instant and free!

UserID or Email:  Enter your account email, permanent UserID, or current display name.
    Remember Me

 Sign Up  Forgot Password?

More Info

Definition:  Abstract Class / Abstract Member


Share a thought or comment...
Write a Comment...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.

Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1207A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101348 Counter
Since 10/24/2008
   Contact Us!
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

590 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...

©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech