Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > C# 2008 aka C# 3.0
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 15th, 2010, 06:58 AM
Authorized User
Points: 403, Level: 7
Points: 403, Level: 7 Points: 403, Level: 7 Points: 403, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Location: Kolkata, India
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default Static class

Why we can not inherit static class??
__________________
Happy coding...

Arnab Roy Chowdhury.
Reply With Quote
  #2 (permalink)  
Old December 15th, 2010, 07:11 AM
samjudson's Avatar
Friend of Wrox
Points: 8,436, Level: 39
Points: 8,436, Level: 39 Points: 8,436, Level: 39 Points: 8,436, Level: 39
Activity: 25%
Activity: 25% Activity: 25% Activity: 25%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,084
Thanks: 1
Thanked 180 Times in 179 Posts
Default

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.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
The Following 2 Users Say Thank You to samjudson For This Useful Post:
MohamedHassanAli (May 24th, 2011)
  #3 (permalink)  
Old December 15th, 2010, 07:45 AM
Authorized User
Points: 403, Level: 7
Points: 403, Level: 7 Points: 403, Level: 7 Points: 403, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Location: Kolkata, India
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Reply With Quote
  #4 (permalink)  
Old December 15th, 2010, 09:00 AM
samjudson's Avatar
Friend of Wrox
Points: 8,436, Level: 39
Points: 8,436, Level: 39 Points: 8,436, Level: 39 Points: 8,436, Level: 39
Activity: 25%
Activity: 25% Activity: 25% Activity: 25%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,084
Thanks: 1
Thanked 180 Times in 179 Posts
Default

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.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #5 (permalink)  
Old December 16th, 2010, 01:09 AM
Authorized User
Points: 403, Level: 7
Points: 403, Level: 7 Points: 403, Level: 7 Points: 403, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Location: Kolkata, India
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Question

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.
Reply With Quote
  #6 (permalink)  
Old December 16th, 2010, 02:46 AM
samjudson's Avatar
Friend of Wrox
Points: 8,436, Level: 39
Points: 8,436, Level: 39 Points: 8,436, Level: 39 Points: 8,436, Level: 39
Activity: 25%
Activity: 25% Activity: 25% Activity: 25%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,084
Thanks: 1
Thanked 180 Times in 179 Posts
Default

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.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #7 (permalink)  
Old April 13th, 2011, 08:38 AM
Authorized User
 
Join Date: Dec 2004
Location: Madurai, Tamil Nadu, India.
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
Send a message via Yahoo to whiterainbow
Default

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.
Reply With Quote
  #8 (permalink)  
Old April 14th, 2011, 02:09 AM
Authorized User
Points: 403, Level: 7
Points: 403, Level: 7 Points: 403, Level: 7 Points: 403, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2009
Location: Kolkata, India
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is there any relation between non-movable members / properies with inheritence?
__________________
Happy coding...

Arnab Roy Chowdhury.
Reply With Quote
  #9 (permalink)  
Old April 14th, 2011, 02:14 AM
Authorized User
 
Join Date: Dec 2004
Location: Madurai, Tamil Nadu, India.
Posts: 69
Thanks: 0
Thanked 5 Times in 5 Posts
Send a message via Yahoo to whiterainbow
Default

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.
Reply With Quote
  #10 (permalink)  
Old May 24th, 2011, 01:20 AM
Authorized User
 
Join Date: Mar 2011
Posts: 17
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by arnab-jit View Post
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Static variables in Static Class JoinTTT BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 4 March 29th, 2009 05:08 PM
Using logging class as a static class punitw General .NET 0 August 14th, 2008 03:03 AM
static field with class instance prakash.suthar Java Basics 2 July 3rd, 2006 01:41 AM
static Class in ASP chafor ASP.NET 1.0 and 1.1 Basics 4 January 13th, 2006 09:58 AM
who destroy static variables(no instance of class) MikoMax J2EE 1 March 31st, 2004 07:01 AM



All times are GMT -4. The time now is 03:48 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.