Yes, methods inside the abstract class can be static.
Interviews14 answers
Can an abstract class have static methods?
14 Answers
vijay kumarPosted Oct 27, 2021, 9:05 AM EDT
Yes You cant have static method as concrete method in abstract class . But not as abstract method cause static method cannot be overridden.
Babita NairPosted Jun 1, 2021, 5:41 AM EDT
Oui
Savatry MilaminaPosted Apr 2, 2020, 2:44 AM EDT
yes
Bidyasagar MishraPosted Aug 3, 2019, 8:56 PM EDT
Yes
pavan kumarPosted May 26, 2019, 3:43 AM EDT
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 here
Console.WriteLine("Hello, world!");
Abstractclass.staticdemo();
}
}
}
result: -
Hello, world!
welcome static method
kajal ranePosted Apr 7, 2019, 12:45 AM EDT
a static member can not in marked as virtual ,override or abstract.
siva bPosted Mar 12, 2019, 8:15 AM EDT
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.
Amit PrakashPosted Jan 1, 2019, 8:53 PM EST
No
abhijeet bhamarePosted Nov 28, 2018, 5:23 AM EST
yes
Bhanuprasad MitturiPosted Nov 20, 2018, 1:00 AM EST
static methods do not have an instance. So, you can have a static method in an abstract class
Naveen BishtPosted Nov 19, 2018, 1:24 AM EST
Yes
Bassam WassoufPosted Nov 14, 2018, 5:11 PM EST
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)
Vikas AgarwalPosted Oct 26, 2018, 3:56 AM EDT
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.
Niloshima SrivastavaPosted Oct 12, 2018, 4:49 AM EDT




