0

So every new class needs the main method? Or just the first one?

24th Feb 2019, 9:53 AM
Georgiana Crețu
19 Answers
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 :)
25th Feb 2019, 9:04 PM
Bahhaāµ£
Bahhaāµ£ - avatar
+ 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.
25th Feb 2019, 12:11 PM
Georgiana Crețu
+ 1
Thanks!
24th Feb 2019, 10:08 AM
Georgiana Crețu
+ 1
Thank you!
25th Feb 2019, 11:47 AM
Georgiana Crețu
+ 1
Aha, thanks #swim
25th Feb 2019, 12:08 PM
Georgiana Crețu
+ 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
25th Feb 2019, 12:08 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
only one main is needed. it is the entry point of the program. other classes need a constructor.
24th Feb 2019, 10:07 AM
Bahhaāµ£
Bahhaāµ£ - avatar
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.
25th Feb 2019, 11:50 AM
Bahhaāµ£
Bahhaāµ£ - avatar
0
But how, calling other functions of other classes in the main will work?
25th Feb 2019, 11:59 AM
Georgiana Crețu
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?
25th Feb 2019, 12:01 PM
Georgiana Crețu
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.
25th Feb 2019, 12:04 PM
Bahhaāµ£
Bahhaāµ£ - avatar
0
I understand that, thanks. I'm just confuse how it will work šŸ˜‚šŸ˜‚... Maybe exercising more I'll get it
25th Feb 2019, 12:06 PM
Georgiana Crețu
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.
25th Feb 2019, 5:57 PM
Bahhaāµ£
Bahhaāµ£ - avatar