0

Can we create object of any other class outside main method??

11th Feb 2020, 2:14 PM
ashish upadhyaya
ashish upadhyaya - avatar
3 odpowiedzi
+ 1
You can create and instantiate objects of classes anywhere inside the class, but to use them inside the main method you'll need to declare them as static.
11th Feb 2020, 2:19 PM
coddy
coddy - avatar
+ 1
From Main, you can direct to another class that handles the creation of objects of another class and even further. Sure. Example: A Game, main method calls a method to create the game items, which is part of another class, for example class ItemBuilder There you might put all the methods concerning items and their creation as well. That's to keep the code readable, changes local and so on but it's easy to overcomplicate it like this
11th Feb 2020, 2:22 PM
Alisa Jääkarhu
Alisa Jääkarhu - avatar
12th Feb 2020, 12:42 AM
Denise Roßberg
Denise Roßberg - avatar