0

What is the difference between sealed and private?

23rd Aug 2016, 5:01 PM
Harish Elumalai
Harish Elumalai - avatar
3 Respuestas
+ 2
Sealed method cannot be overridden in subclass. It's useful when you have a base class A with virtual method, subclass B based on A which overrides this virtual method, and subclass C based on B which cannot override this virtual method because class B sealed it. Class C can still use it, because it should have protected or public modifier (if I remember right you cannot write private virtual methods). You can also seal classes. Such classes cannot be used as a base class.
27th Aug 2016, 6:01 AM
Ivan G
Ivan G - avatar
+ 1
If you are pertaining to their usage for methods: sealed modifier prevents a derived class from overriding the method. While private modifier makes methods accessible only by code in the same class or struct.
23rd Aug 2016, 6:13 PM
Erwin Mesias
Erwin Mesias - avatar
0
if method is sealed we can use it in derived class?
24th Aug 2016, 1:11 AM
Harish Elumalai
Harish Elumalai - avatar