+ 2
what will happen if we declare instance of static classes? will it give compile time error or run time?
5 Answers
+ 1
it will give you a compile time error because static classes can not be instantiated. The methods of static classes are used by calling them with the class name using period(.) operator.
An upvote will be highly appreciated.....
0
@Aastha, I'll give you an UpVote for that.
Here: 👍
0
oh C'mon @Erwin😂😂😂😂
0
so wats the importance of this static class? why we should use it?
0
@Souradip The importance is its main feature. You don't have to make an object to access its methods because you can use them by referring to the name of the class itself.
example-
static class Shape
{
public static double GetArea(double Width, double height)
{
return Width * Height;
}
}
class Rectangle
{
private void GetRectangleArea()
{
Double Area;
Area = Shape.GetArea(10, 5);
}
}
now here we didn't create an object of the class Shape because it is a static class so we accessed the method GetArea by using Shape.GetArea(10,5);