Final keyword in C#
Aug 26, 2023 am 08:33 AMJava has the final keyword, but C# does not have its implementation. For the same implementation, use the seal keyword.
Using seal, you can prevent methods from being overridden. When you use the sealed modifier on a method in C#, the method loses its override functionality. The Sealed method should be part of the derived class and the method must be an overridden method.
The following example does not allow you to override the method display() because it has the seal modifier of the ClassTwo derived class.
ClassOne is our base class, while ClassTwo and ClassThree are derived classes -
Example
class ClassOne { public virtual void display() { Console.WriteLine("Baseclass"); } } class ClassTwo : ClassOne { public sealed override void display() { Console.WriteLine("ClassTwo:derivedClass"); } } class ClassThree : ClassTwo { public override void display() { Console.WriteLine("ClassThree: Another Derived Class"); } }
The above is the detailed content of Final keyword in C#. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What are the alternatives to NULL in C language

Method of copying code by C language compiler

What are the web versions of C language compilers?

Is NULL still important in modern programming in C language?

C language online programming website C language compiler official website summary

C language compiler installation tutorial (computer version)
