 |
| C# 2008 aka C# 3.0 Discuss the Visual C# 2008 (aka C# 3.0) language |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# 2008 aka C# 3.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 15th, 2010, 07:58 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Static class
Why we can not inherit static class??
__________________
Happy coding...
Arnab Roy Chowdhury.
|
|

December 15th, 2010, 08:11 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I don't suppose the answer 'because its static' is enough for you huh?
You might as well ask, why can't I walk through this wall here - why do I have to use the door over there instead - well, because whoever designed the house put the wall there and the door over there for a reason.
|
|
The Following 2 Users Say Thank You to samjudson For This Useful Post:
|
|
|

December 15th, 2010, 08:45 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Static means a class that have only static members and we can not create any object with that class. But the point is why Microsoft is not allowing us to extends the static class with another static class?
__________________
Happy coding...
Arnab Roy Chowdhury.
|
|

December 15th, 2010, 10:00 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I know what static means. Microsoft (or any developer) makes a class static specifically because they don't want you to inherit from it.
So ask yourself why you want to inherit from a static class.
|
|

December 16th, 2010, 02:09 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
By inheriting a class we can create one or more specific functionality. For example 'Animal' to 'Dog'. But if the Animal and Dog class are static, then what will be the problem? Why we can not extends the static functionality?
One thing is that we can not create any object for static class. So by inheriting them we can not do any dynamic polymorphism with that. Brcause dynamic polymorphism is totally based on runtime object type. It will be a good reason to not allowinging static class in inheritence.
Am I right?
__________________
Happy coding...
Arnab Roy Chowdhury.
|
|

December 16th, 2010, 03:46 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I'm still not 100% sure where you are coming from on this but I think you are over thinking it. You would never create a static class around a concept like 'Animal' or 'Dog' in the first place, as these are not static concepts.
|
|

April 13th, 2011, 08:38 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
The static means that it is non-changeable or non-moveable. So what you are going to do with the non-changeable members of a static class? Animals will have a lot of properties and the Dog will inherit a few properties of animal then why you are not using an interface to extend the properties of Animal. In any language, the static class is non-extendable...
__________________
Thanks in advance.
Regards,
Senthil Kumar M.
|
|

April 14th, 2011, 02:09 AM
|
|
Authorized User
|
|
Join Date: Jun 2009
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is there any relation between non-movable members / properies with inheritence?
__________________
Happy coding...
Arnab Roy Chowdhury.
|
|

April 14th, 2011, 02:14 AM
|
|
Authorized User
|
|
Join Date: Dec 2004
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
|
|
Yes. Non-movable properties cannot be overridden... You just can use the functionality but not change the functionality...
__________________
Thanks in advance.
Regards,
Senthil Kumar M.
|
|

May 24th, 2011, 01:20 AM
|
|
Authorized User
|
|
Join Date: Mar 2011
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by arnab-jit
Why we can not inherit static class??
|
Becoz they are Sealed and Abstract :)
static class stTest{}
Check the IL code for this
you will see the a static class in sealed and abstract
|
|
 |