Is it possible to create an object that would be constructed from the class it's was calling from, or it is a loop. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it possible to create an object that would be constructed from the class it's was calling from, or it is a loop.

7th Sep 2016, 3:33 PM
buran9
buran9 - avatar
4 Answers
+ 1
Are you describing instanciation or is there something I didn't get? MyClass myObj = new MyClass();
7th Sep 2016, 3:47 PM
Zen
Zen - avatar
+ 1
Yes you can, and yes it has the potential to create an infinite loop. Common question is if it's done in the main method what happens, in such case, it doesn't create an infinite loop since main only gets called once as an instance since it's static.
8th Sep 2016, 3:05 AM
James
James - avatar
0
lookup recursion.
7th Sep 2016, 4:21 PM
Alex Wood
Alex Wood - avatar
0
all examples with recursion are with method recursion, and what if: class MyClass { ... MyClass myObj = new MyClass(); ... }
7th Sep 2016, 6:28 PM
buran9
buran9 - avatar