You must Sign In to post a response.

difference between static and sealed classes?

difference between static and sealed classes?


Comments

#260596    Author: lalitha  08 Jul 2008 Member Level: Gold   Points : 1

http://www.dotnetspider.com/forum/118043-Difference-between-static-sealed-classes.aspx

#260599    Author: Ratheesh    08 Jul 2008 Member Level: Gold   Points : 1

Static classes

Static classes are used when a class provides functionality that is not specific to any unique instance. Here are the features of static classes in C# 2.0.

Static classes can not be instantiated.
Static classes are sealed so they can not be inherited.
Only static members are allowed.
Static classes can only have static constructor to initialize static members.



sealed classes

when a class defined as sealed its not possible to inherit
its class and properties to the inherited class.Its also
applicable to the class properties.Even class defined as
public its banned to inherit the class.

#260600    Author: sivangari    08 Jul 2008 Member Level: Gold   Points : 6

hi,
Static class:
A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.

Sealed Class:
when a class defined as sealed its not possible to inherit
its class and properties to the inherited class.Its also
applicable to the class properties.Even class defined as
public its banned to inherit the class.

#260602    Author: Ebenezer  08 Jul 2008 Member Level: Silver   Points : 0

Sealed cannt be inherit by other..

#260605    Author: Roopesh Babu Valluru  08 Jul 2008 Member Level: Gold   Points : 3

class which cannot be inherited is called sealed class....

class with atleast one method WITH OUT FUNCTIONALLITY is called as static class...it should be inherited and provide functionallity in derived class....

All The Best...

#260690    Author: chandramohan  08 Jul 2008 Member Level: Gold   Points : 1

Static class:
A class can be declared static, indicating that it contains only static members. It is not possible to create instances of a static class using the new keyword. Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.

The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created.

Static classes are sealed and therefore cannot be inherited. Static classes cannot contain a constructor, although it is still possible to declare a static constructor to assign initial values or set up some static state.

Sealed Class:
when a class defined as sealed its not possible to inherit
its class and properties to the inherited class.Its also
applicable to the class properties.Even class defined as
public its banned to inherit the class.

#265950    Author: Ultimaterengan  18 Jul 2008 Member Level: Gold   Points : 1

Static classes are used when a class provides functionality that is not specific to any unique instance. Here are the features of static classes in C# 2.0.

Static classes can not be instantiated.
Static classes are sealed so they can not be inherited.
Only static members are allowed.
Static classes can only have static constructor to initialize static members.

Advantages

Compiler makes sure that no instance of static class is created. In previous version of C#, the constructor has to be marked private to avoid this from happening.

Also compiler makes sure that no instance members are declared within a static class.




Thanks & Regards
G.Renganathan
Nothing is mine ,Everything is yours!!!


This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.