Hello, friends
I need to call main method of a class from another class. Can you provide one simple code example? It would be nice if you could help me in this.
Best regards,
Roberts
Hello, friends
I need to call main method of a class from another class. Can you provide one simple code example? It would be nice if you could help me in this.
Best regards,
Roberts
It’s exactly the same as calling any other static method - use the class name, :: operator, the method name and parameters. For example:
MyClass::main(...);
If you look at the parameters of main() method, you’ll see that it expects a single Args object. Therefore create an object and pass it to the method (or use null, if the method doesn’t need the value).
Args args = new Args();
MyClass::main(args);