Andrei Zhukouski
Andrei Zhukouski

Reputation: 3506

Is it possible to override method of sealed class?

In WinRT (C#, XAML), ScrollViewer is a sealed class, and I can't extend it, but I need to overwrite some methods (for example: ScrollToHorizontalOffset).

Is it possible to override methods of a sealed class?

Upvotes: 8

Views: 7266

Answers (4)

Sealed itself means that class can not be inherit and those class which can not be inherit means can not be access any property of that class in derived class.

Upvotes: 1

Sai Avinash
Sai Avinash

Reputation: 4753

As the word "sealed" itself indicates that , it is protected from being inherited or overridden

So, No inheritance implies no Overriding.

please find this link to find more details about sealed class in detail.

Upvotes: 3

Habib
Habib

Reputation: 223322

You can't inherit from a sealed class, so no inheritance, no override.

See: override C#

The override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.

See: sealed C#

When applied to a class, the sealed modifier prevents other classes from inheriting from it.

Upvotes: 7

Jon Skeet
Jon Skeet

Reputation: 1502606

No - in order to override a method, you have to derive from it, which you can't do when the class is sealed.

Basically, you need to revisit your design to avoid this requirement...

Upvotes: 17

Related Questions