473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

WHY?? a class cannot be both static and sealed

Maybe I am missing something really elementry here - but why can a sealed
class not be marked as static? (Even though it can contain all static
members?) ... hmmmmm !!

PS: This is .NET 2.0

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Nov 16 '05 #1
6 6737
Maybe I am missing something really elementry here - but why can a sealed
class not be marked as static? (Even though it can contain all static
members?) ... hmmmmm !!


Static classes don't have any constructors, so they can't be
instantiated or derived from anyway. Thus there's no need to mark it
as sealed.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Aha .. okay .. makes sense now !!!

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:#y**************@TK2MSFTNGP09.phx.gbl...
Maybe I am missing something really elementry here - but why can a sealed
class not be marked as static? (Even though it can contain all static
members?) ... hmmmmm !!


Static classes don't have any constructors, so they can't be
instantiated or derived from anyway. Thus there's no need to mark it
as sealed.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #3
The static keyword has stronger semantics (not only can you not
inherit from a static class, you can't create an instance). See the
section 'Static Classes in the .NET Framework 2.0' here:
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 16 Dec 2004 14:01:17 -0500, "Sahil Malik"
<co*****************@nospam.com> wrote:
Maybe I am missing something really elementry here - but why can a sealed
class not be marked as static? (Even though it can contain all static
members?) ... hmmmmm !!

PS: This is .NET 2.0

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


Nov 16 '05 #4
Thanks Scott !!

- SM

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:18********************************@4ax.com...
The static keyword has stronger semantics (not only can you not
inherit from a static class, you can't create an instance). See the
section 'Static Classes in the .NET Framework 2.0' here:
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 16 Dec 2004 14:01:17 -0500, "Sahil Malik"
<co*****************@nospam.com> wrote:
Maybe I am missing something really elementry here - but why can a sealed
class not be marked as static? (Even though it can contain all static
members?) ... hmmmmm !!

PS: This is .NET 2.0

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik

Nov 16 '05 #5
A class modifier can be used only once.

with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6
I have to add to my previous post. Static is a class modifier in .Net
2.0 and is a method modifier in .Net 1.x and hence cannot be used with a
class.

Please modify my previous answer.
with regards,
J.V.Ravichandran
- http://www.geocities.com/
jvravichandran
- http://www.411asp.net/func/search?
qry=Ravichandran+J.V.&cob=aspnetpro
- http://www.southasianoutlook.com
- http://www.MSDNAA.Net
- http://www.csharphelp.com
- http://www.poetry.com/Publications/
display.asp?ID=P3966388&BN=999&PN=2
- Or, just search on "J.V.Ravichandran"
at http://www.Google.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
7
by: yufufi | last post by:
lets say we have a 'shape' class which doesn't implement IComparable interface.. compiler doesn't give you error for the lines below.. shape b= new shape(); IComparable h; h=(IComparable)b;...
8
by: Keith Henderson | last post by:
I know I sound like a dolt for asking, but if I have a few functions that any objects in my code can call, mostly these are functions, how do I make them public to the application? I'm confused...
15
by: ad | last post by:
We can define a static member in a class. But can we define a static class, so that all members are static?
3
by: Phillip Ian | last post by:
Just a quick architecture question. I'm just looking for discussion, not a flame war, please. In the past, I've tended to use a public module for my data layer functions. Something like: ...
5
by: Tina | last post by:
I'm using C# 1.1.............. I add new Class item to my project. It's created as class Math I change it to public static class Math I get an error saying that "The modifier 'static' is...
8
by: Bern McCarty | last post by:
I have a simple ref class in its own namespace that needs to coexist with a legacy typedef alias for "unsigned int" in the global namespace that has the identifier as itself. Everything compiles...
3
by: archana | last post by:
Hi all, I have created one sealed class having one constant. Can i access that constant of sealed class without creating object of that class. If yes will internally new object gets created....
1
by: =?Utf-8?B?d3BjbWFtZQ==?= | last post by:
Why does the following code public ref struct X abstract sealed { literal int Y = 1; }; give the error C4693: 'X' a sealed abstract class cannot have any instance members 'Y'? In the help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.