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?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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 } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |