Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
Can some one provide a couple of examples of real life usage of the sealed keyword? Thank you.
Posted
Updated 27-Oct-10 4:04am
v2

Sealed class cannot be inherited and any attempts to inherit the sealed class will result in error, you need to do homework on this;

here's a link which explains sealed class

Sealed class explanation

and to make your work easy i have googled it for you

Sealed class real life examples


Don't forget to mark this answer if you find it useful

Thanks and Regards
Radix :rose:
 
Share this answer
 
Comments
Dalek Dave 27-Oct-10 10:13am    
You let him off too easily!
As Toli has replied already, sealed classes are expected to have a slight performance advantage during JIT. It's not as good a difference as people expect it to be, so that should not be the deciding reason to make a class sealed.

Since a sealed class will not have child classes, the JIT compiler can safely generate call IL instructions instead of callvirt IL instructions when it is sure that the instance on which the call is made is non-null. So even if it's invoking a virtual method, if it knows for certain that the object is non-null, it can emit a call instruction which is faster than a callvirt instruction.

Once again, do not use this as a basis to seal your class. Do that only if you think it's the best choice for your class hierarchy.
 
Share this answer
 
v2
Generally in real world enviornment the third party rendors can use .Net dll files and inherit the classes by creating a new software,So in this case to protect the classes declared as a sealed and protected access modifiers,Sealed class is also useful to restrict the hierarchy of inheritance.

Please vote and Accept Answer if it Helped.
 
Share this answer
 
Comments
Prakash Kumar 27 23-Dec-14 0:30am    
onion
Now, I guess it's too much of your homework question here on forum. Please stop flooding the forum with your basic questions, probably a part of your homework assignment. Read, learn, Google...

If you really know what 'sealed' keyword does then you can put many examples by yourself.
 
Share this answer
 
1. Speed!
A sealed class is instanciated slightly faster.
2. Block / Annoy!
No one can easily enrich your class.
 
Share this answer
 
Comments
Nish Nishant 27-Oct-10 10:05am    
This is actually the most accurate reply. Unfortunately, someone downvoted it. I propose this as answer.
RaviRanjanKr 27-Oct-10 10:13am    
Agree to Nishant
Toli Cuturicu 27-Oct-10 10:17am    
Thanks. It happens sometimes. For example, the OP does not understand the answer, or overlloks it and downvotes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900