what will happen if we declare instance of static classes? will it give compile time error or run time? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

what will happen if we declare instance of static classes? will it give compile time error or run time?

10th Jul 2016, 2:46 PM
Souradip Das
Souradip Das - avatar
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.....
11th Jul 2016, 10:32 AM
Aastha Aneja
Aastha Aneja - avatar
0
@Aastha, I'll give you an UpVote for that. Here: 👍
11th Jul 2016, 7:46 PM
Erwin Mesias
Erwin Mesias - avatar
0
oh C'mon @Erwin😂😂😂😂
12th Jul 2016, 6:07 AM
Aastha Aneja
Aastha Aneja - avatar
0
so wats the importance of this static class? why we should use it?
12th Jul 2016, 6:29 AM
Souradip Das
Souradip Das - avatar
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);
12th Jul 2016, 6:37 AM
Aastha Aneja
Aastha Aneja - avatar