0

When calling a method from the main, the method has to be static?

If I create a method at my principal class, where the main is, and call it from the main, the method has to be static? why? I understand what a static variable is but I can't completely understand the static methods

12th Jun 2017, 1:46 AM
Daniel Leonard
Daniel Leonard - avatar
1 Answer
+ 1
to call a method from main, it either needs to be static, or it needs to be called from an instance of your class. like this, ClassName abc = new ClassName(); // insert constructor arguments if required abc.nonStaticMethod(); it is perfectly normal to create an instance of the same class the main method belongs to inside the main function.
12th Jun 2017, 2:18 AM
Nikunj Arora
Nikunj Arora - avatar