Reputation: 23
okay, i hope i can explain my question so its not hard to understand, i want to know if i can create an instance of a class in my main class but im not sure if the constructor of the second class lets my main class continue while the second class is busy with its constructor.
the reason i want to know this is, i want to access the data of the second class on the second line of my main class (right after the second class has been initiated) sorry for this weird question, i hope i didn't too bad explaining my question (im fairly new to it) thanks for reading!
Upvotes: 2
Views: 119
Reputation: 5794
will java wait till the second class's constructor is done, then move to the next line of code?
Yes. Your application will run in a single thread by default (though it is possible to change this behavior). This means anything that happens in your code - method calls, loops, any calculation - they will occur serially; one thing after the other.
Upvotes: 1
Reputation: 159165
Unless you explicitly create multi-threading (by using any of the various ways Java supports for that), all the code runs in a single thread, so calling a constructor will always wait until the constructor is done.
Upvotes: 1