+ 1

Can someone describe to me the exact use of static keyword before main module?

I will understand in programming terms as i know C language very well.

15th Dec 2016, 5:22 PM
Rohit thapliyal
Rohit thapliyal - avatar
3 Answers
+ 8
In order to use a method inside of a class, an object for that class must be instantiated. Unless the method is made static, in which case, it can be called without an object. Since main() is inside a class, it must be made static. You can't instantiate an object for its class before the program even starts, can you?
15th Dec 2016, 5:50 PM
Tamra
Tamra - avatar
+ 6
An object is declared from a class. That class is like a blueprint for an object, which describes what behaviors the object can do (methods), and what data properties it has (variables). Ex: You can have a BankAccount class with an ID, UserName, and Balance as its properties/data, and OpenAccount(), CloseAccount(), Deposit(), and Withdraw() as its behaviors/methods. Every object can access the methods and has its own set of properties. Making a module (a class or method) static eliminates the need to access a class's methods through an object. Methods and properties can also be declared as private or public (there's also protected but that's a more advanced topic). Private means that it can only be used inside the class. Public means it can be accessed through any object.
16th Dec 2016, 8:37 AM
Tamra
Tamra - avatar
0
@Tamra Can you please tell me what an object is? And how is a module made static, what if we use something other than static.
16th Dec 2016, 8:24 AM
Rohit thapliyal
Rohit thapliyal - avatar