Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C#4.0 oops
Hi Dear friend ,
 
I have one question
 
i have study both class static or sealed class
 
1)Both class can't be inheritance
2)we can not create object
3) we directly use by name
 
but what is the differences in these two class
 
i think all this answer as fresher level .
but i want answer as a experience person
 

Thanks in advance
Anil kumar
Posted 18-Sep-11 21:56pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Sealed classes: 
1)Can create instances, but cannot inherit
2)Can contain static as well as nonstatic members.
 
Static classes:
1)Can neither create their instances, nor inherit them
2)Can have static members only.
  Permalink  
Comments
RaisKazi at 19-Sep-11 5:18am
   
my 5!
Shambhoo kumar at 28-Jan-13 6:57am
   
great difference...thanks alot..
my 5!
:)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

1. A Sealed class cannot be inherited from and can static and non-static members or methods. Contains a public constructor.
2. A Static class cannot be inherited from and contains only static methods and class properties. Contains a private constructor.
  Permalink  
Comments
Preethi PS at 22-Aug-12 3:08am
   
Why cant a static class be inherited?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

They are completely different.
 
A sealed class cannot be inherited: that is it's only difference from any other type of class.
 
A static class cannot be instantiated. You cannot, at any time write new MyStaticClass() without the compiler complaining. It never has a this reference, and the fields, properties and methods can only ever be accessed via the class name: MyStaticClass.MyMethod() In addition, you cannot derive from a static class, not can a static class derive from any class other than object
  Permalink  
Comments
RaisKazi at 19-Sep-11 5:19am
   
my 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

A static class can only contain static Methods, Properties and Fields and what you wrote in 1), 2) and 3) applies.
A sealed class is a normal class which you can make an instance of, but you cannot inherit from it. what you wrote in 2) and 3) does not apply to sealed classes, tough a sealed class can have static methods and thus you can argue 3) applies.
 
For a more indepth view see Static Classes and Static Class Members[^], sealed (C# Reference)[^] and Abstract and Sealed Classes and Class Members[^]
  Permalink  
v2
Comments
RaisKazi at 19-Sep-11 5:18am
   
my 5!
Simon Bang Terkildsen at 19-Sep-11 7:43am
   
Thank you, Rais
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

* A static class can only contain static members (it is just a container for methods that do not logically belong to an instance of any standard class)
      * An abstract class can cotnain all usual kinds of members (static, abstract and also instance)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100