+ 1

Static methods

can any one explain to me why the methods in the main class should be a static methods

29th Nov 2016, 4:21 PM
abdulmalek dery
abdulmalek dery - avatar
1 Answer
+ 6
A static method is a method that we can access it without creating an object of that class that method is in , so when you compile your code the compiler looks for the main method so it must be declared as static othervise the compiler can't access it without object so a compile time error will ocur. Beacuse of that we need to declare the main class a s static so the compiler can access it without creating an object
29th Nov 2016, 4:28 PM
( ͥ° ͜ʖ ͥ°)