I have two classes one abstract and another is normal class. and both are having static methods and calling same way and producing result successfully.
Abstract class static method:
public abstract class AbstA
{
public static void Print()
{
Console.WriteLine("Abstract Class static method");
}
}
Normal class static method:
public class NormalA
{
public static void Print()
{
Console.WriteLine("Normal Class static method");
}
}
Both are successfully running.
AbstA.Print();
NormalA.Print();
So what is difference between both classes?
抽象类和常规类中的静态方法没有区别,因为静态方法是在不实例化类的情况下调用的。
There is no difference between abstract classes , normal classes and even static classes when you want use static members of them. Difference is when you want instantiate each of them.
You can instantiate it. Like any normal class that you may have.
You cannot instantiate it. When you have an abstract class, you can have class members(methods, properties) that are not implemented. Because of that you can not instantiate it. If you want to know more about abstract classes visit this link
You cannot instantiate it. When a class is static it can just contain members that are static. so you cannot instantiate it. If you want to know more about static classes visit this link
In awnser to your question: there is no difference for the static methods. What they are housed in doesn't matter.
The keyword abstract is used if if it's meant to be used as a base class to something else Ie have shoe as an abstract class, and trainer (type of shoe) as a class that inherits from shoe. This doesn't not affect the methods inside
Hope this makes sense
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.