Skip to Content
Programming Visual Basic .NET, Second Edition
book

Programming Visual Basic .NET, Second Edition

by Jesse Liberty
April 2003
Intermediate to advanced
560 pages
14h 4m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET, Second Edition

Abstract Methods and Classes

Each type of Window has a different shape and appearance. Drop-down list boxes look very different from Buttons. Clearly, every subclass of Window should implement its own DrawWindow( ) method—but so far, nothing in the Window class enforces that they must do so. To require subclasses to implement a method of their base, you need to designate that method as abstract.

You designate a method as abstract by placing the MustOverride keyword at the beginning of the method definition, as follows:

MustOverride Public Sub DrawWindow ( )

An MustOverride method has no implementation. It creates a method name and signature that must be implemented in all derived classes. Furthermore, making one or more methods of any class MustOverride has the side effect of making the class abstract; an abstract class must be marked with the keyword MustInherit .

Classes marked with MustInherit establish a base for derived classes, but it is not legal to instantiate an object of a class marked MustInherit. Once you declare a method with MustOverride, you prohibit the creation of any instances of that class.

If one or more methods of the class are MustOverride, the class definition must be marked MustInherit, as in the following:

MustInherit Public Class Window

Thus, if you were to designate DrawWindow( ) MustOverride in the Window class, the Window class would thus become MustInherit. Then you could derive from Window, but you could not create any Window objects/instances. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Visual Basic .NET

Programming Visual Basic .NET

Dave Grundgeiger
VB.NET Language in a Nutshell, Second Edition

VB.NET Language in a Nutshell, Second Edition

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596004389Supplemental ContentCatalog PageErrata