0
Can we create object of any other class outside main method??
3 Answers
+ 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.
+ 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
+ 1
ashish upadhyaya
Here is a small example:
https://code.sololearn.com/cIQ5s0ricV6c/?ref=app