IT Community - Software Programming, Web Development and Technical Support

Can static methods be overridable?

This is a discussion on Can static methods be overridable? within the C# Programming forums, part of the Software Development category; Can static methods be overridable?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-26-2007, 08:23 AM
sivakumar sivakumar is offline
D-Web Trainee
 
Join Date: Jul 2007
Posts: 36
sivakumar is on a distinguished road
Question Can static methods be overridable?

Can static methods be overridable?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 01:29 PM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: Can static methods be overridable?

We cannot override static methods in C#. and we can't be marked as virtual or abstract. But it is possible to hide a base class static method in a derived class by using the keyword new.

For An example

using System;
class A
{
public static int z = 25;
public static void WriteZ()
{
Console.WriteLine("Super class static method");
}

}

class B : A
{
public new static int z = 50;
public new static void WriteZ()
{
Console.WriteLine("Derived class static method");
}
}

class C
{
public static void Main()
{
B.WriteZ(); // It will Display 'Derived class static method'
Console.WriteLine(B.z); // Displays 50
}
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Static members ragavraj PHP Programming 2 12-06-2007 08:17 PM
Static IP & Dynamic IP vadivelanvaidyanathan Server Management 0 07-15-2007 06:53 PM
Static Global Variable and Static Local Variable vigneshgets C and C++ Programming 1 05-30-2007 11:50 AM
difference between a static and a non-static inner class vigneshgets Java Programming 1 05-23-2007 11:02 PM
Java Static swoosh Java Programming 3 05-08-2007 04:36 AM


All times are GMT -7. The time now is 11:20 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0