How do you add the classes without adding another main method? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How do you add the classes without adding another main method?

Java Classes

13th Sep 2019, 9:13 AM
66:101:110:74:97:109:105:110
66:101:110:74:97:109:105:110 - avatar
6 Answers
13th Sep 2019, 11:10 AM
Dominique Abou Samah
Dominique Abou Samah - avatar
+ 6
You only need 1 class with 1 main method inside of it any other class you create can be without. 1) Class program{ 1) main method(){ do stuff } } //my other classes, these are outside of the class that the main method is inside of. Class MyClass1{do stuff} Class MyClass2{do stuff} Class MyClass2{do stuff}
13th Sep 2019, 12:00 PM
D_Stark
D_Stark - avatar
+ 1
Please be more specific, do you wanna create new classes or add instances of these classes?
13th Sep 2019, 10:54 AM
Dominique Abou Samah
Dominique Abou Samah - avatar
+ 1
To write a java class, you write it outside the main class. Now to create an instance of a class, it can be done in the main method using the "new" operator. You can also create instances inside other classes depending on what you wanna do. But each class should be dependent by itself
13th Sep 2019, 11:02 AM
Dominique Abou Samah
Dominique Abou Samah - avatar
0
@Dominique Abou Samah If you don't mind, please show me how to do both.
13th Sep 2019, 11:00 AM
66:101:110:74:97:109:105:110
66:101:110:74:97:109:105:110 - avatar
0
Dominique Abou Samah Please illustrate it using a code. I'll appreciate it a lot.
13th Sep 2019, 11:04 AM
66:101:110:74:97:109:105:110
66:101:110:74:97:109:105:110 - avatar