0
So every new class needs the main method? Or just the first one?
19 Respuestas
0
~ swim ~ right, I think you didn't quite get the question or I didn't . he is a beginner and he thought that evey class you create has to have a main method. the thread you referred to is about running multiple programs and is kind of advanced.
he was asking about the necessity and you're talking about the possibility.
great discussion though :)
+ 2
😂😂 My English is bad. I understand now. I can use one main or more(but not recommended) and when i call a method i have to use obj. method and the main will know wich class i refer to.
+ 1
Thanks!
+ 1
Thank you!
+ 1
Aha, thanks #swim
+ 1
you can call other methods by using an object of the class or by using the class name to call static methods.
your first question is confusing
0
only one main is needed. it is the entry point of the program. other classes need a constructor.
0
there is no need to use multiple main in a single program. one is enough, although you can use them but they can't be the same. using two identical main will not compile.
0
But how, calling other functions of other classes in the main will work?
0
I mean i can't see how. Because we use main only in that class. When we close {} can the method main use information from other class?
0
answering your question (does every class need a main method?) the answer is no although you can. it doesn't even make sense to use many main especially for a beginner.
0
I understand that, thanks. I'm just confuse how it will work 😂😂... Maybe exercising more I'll get it
0
~ swim ~ by overloading. it can be overloaded like any other functions but they have to be called inside the Main function. the
public static void main(String[] args) is hard-coded in JVM and it should be used.
we have gone too far from the original question.
what I understood from the main question is, he doesn't know whether it is needed to use a main in every class beside the main program. so I said no without going into detail until you said he could.