+ 1
What is happening with the code?
See the code below. Is this a correct practise, or is it working by luck? My class contains an object of its own type, which in turn has an object of its own type,..... So it's wrong right? Or am I missing something? https://code.sololearn.com/cWYb2H95Onvy/?ref=app
2 Respostas
+ 2
Your program is fine.
If the code is small and you don't need multiple classes, it is OK to have the main method inside that same class that you are also instantiating.
When you create a more complex program where each class is in a separate file, then the class containing your main method can be as pure as possible, and only be used to control the program execution flow, without being instantiated itself.
0
Tibor Santa what about the "My class contains an object of its own type, which in turn has an object of its own type,....."?