I had all the rest of the code ready, and when I wanted to call the joinData method I found out that I couldn't.
Only when instantiating the Solution class I was able to call the method on the instance. In this case, I really don't understand why, can someone explain it to me?
Thanks in advance.
Why do we need to we need to create an instance of Solution to call the joinData method?
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
daydreaming
2 April 2020, 09:41
Bucause the method joinData() is not a static method.
The non-static mothod doesn't exist before an instance of the class Solution. It could be only invoked by an instance of the class.
However ,the method main() must be static. In the main method you want to invoke a non-static class? no, impossible , it doesn't exist at that time. That could also explain why static method could only invoke static method.
To fix it , make the method static or create an instance of the class.
+2