Niloshima Srivastava
Can an abstract class have static methods?
By Niloshima Srivastava in C# on Oct 12 2018
  • Niloshima Srivastava
    Oct, 2018 12

    Yes, abstract class can have Static Methods. The reason for this is Static methods do not work on the instance of the class, they are directly associated with the class itself. So if you write a static method in the class and compile it, and when you try to view the IL, it will be same as any other class accessing the static member.

    • 6
  • Amit Prakash
    Jan, 2019 2

    However, for the same reason, you can't declare a static method to be abstract. Normally, the compiler can guarantee that an abstract method will have a real implementation any time that it is called, because you can't create an instance of an abstract class. But since a static method can be called directly, making it abstract would make it possible to call an undefined method.

    • 2
  • Vikas Agarwal
    Oct, 2018 26

    We actually override static methods, it's a bit ugly, but it works just fine for our needs. ... Abstract methods require an instance, but static methods do not have an instance. So, you can have a static method in an abstract class, it just cannot be static abstract (or abstract static)

    • 2
  • kajal rane
    Apr, 2019 7

    Yes,Because static method can be invoked without creating the instance of the class. eg. namespace Rextester {public abstract class Abstractclass{public static void staticdemo(){Console.WriteLine("welcome static method ");}}public class Program{public static void Main(string[] args){//Your code goes hereConsole.WriteLine("Hello, world!");Abstractclass.staticdemo();}} }result: - Hello, world! welcome static method

    • 1
  • vijay kumar
    Oct, 2021 27

    Yes, methods inside the abstract class can be static.

    • 0
  • Babita Nair
    Jun, 2021 1

    Yes You cant have static method as concrete method in abstract class . But not as abstract method cause static method cannot be overridden.

    • 0
  • Savatry Milamina
    Apr, 2020 2


    • 0
  • Bidyasagar Mishra
    Aug, 2019 4


    • 0
  • pavan kumar
    May, 2019 26


    • 0
  • siva b
    Mar, 2019 12

    a static member can not in marked as virtual ,override or abstract.

    • 0
  • abhijeet bhamare
    Nov, 2018 28


    • 0
  • Bhanuprasad Mitturi
    Nov, 2018 20


    • 0
  • Naveen Bisht
    Nov, 2018 19

    static methods do not have an instance. So, you can have a static method in an abstract class

    • 0
  • Bassam Wassouf
    Nov, 2018 14


    • 0

Most Popular Job Functions