+ 1
How do you add the classes without adding another main method?
Java Classes
6 Antworten
+ 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}
+ 1
Please be more specific, do you wanna create new classes or add instances of these classes?
+ 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
0
@Dominique Abou Samah If you don't mind, please show me how to do both.
0
Dominique Abou Samah Please illustrate it using a code. I'll appreciate it a lot.