What will happen if we write non-static method inside static class?

 Posted by vishalneeraj-24503 on 1/23/2014 | Category: C# Interview questions | Views: 1009 | Points: 40
Answer:

First of all we can not write non-static methods inside static class,but if we try to write non-static methods inside static classes,then we will get compile-time error as:

'Method': cannot declare instance members in a static class

Meaning that if we write non-static methods,then we have to access this method by creating object of class,and as static classes do not have instance constructor.So how can we access non-static methods.that's why we can not write non-static methods inside static class.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response