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
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.