IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesVB.Net  Print This     

Prevent Derivation (VB.Net and Java Cross Reference Guide)

By Mike Prestwood

VB.Net versus Java: A side by side comparison between VB.Net and Java.

 
OOP Details
 

More object oriented (OO) stuff.

Prevent Derivation

[Other Languages] 

Languages Focus

How do you prevent another class from inheriting and/or prevent a class from overriding a member.

VB.Net:   NotInheritable, NotOverridable

With VB.Net, use the NotInheritable keyword to prevent a class from being inherited from and use the NotOverridable keyword to prevent a method from being overridden.

A method marked NotOverridable must override an ancestor method. If you mark a class NotInheritable, all members are implicitly not overridable so the NotOverridable keyword is not legal.

Syntax Example:
Public Class Machine
  Public Overridable Sub Speak(ByRef pSentence As String)
MessageBox.Show(pSentence)
End Sub
End Class
  
Public Class Robot
Inherits Machine
  Public NotOverridable Overrides Sub Speak(ByRef pSentence As String)
MessageBox.Show(pSentence)
End Sub
End Class
  
Public NotInheritable Class Cyborg
Inherits Robot
End Class
Java:  "final class" Final

In Java, there is the concept of a final class.

More Info / Comment












Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]