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 GuidesJava  Print This     

Prevent Derivation (Java and C# Cross Reference Guide)

By Mike Prestwood

Java versus C#: A side by side comparison between Java and C#.

 
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.

Java:  "final class" Final

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

More Info / Comment
C#:   sealed

With C#, use the sealed keyword to prevent a class from being inherited from and to prevent a method from being overridden.

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

Syntax Example:
public class Machine : System.Object
{
public virtual void Speak(String pSentence)
{
MessageBox.Show(pSentence);
}
}

public class Robot : Machine
{
public sealed override void Speak(String pSentence)
{
MessageBox.Show(pSentence);
}
}
  
public sealed class Cyborg : Robot
{
}












Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


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