educative.io

Volatile keyword confusion

What will happen even if the volatile instance superman is not constructed completely, then also other threads will skip the first null check and get the incomplete superman object, which will throw error when we use it?


Type your question above this line.

Course: https://www.educative.io/collection/5307417243942912/5707702298738688
Lesson: https://www.educative.io/collection/page/5307417243942912/5707702298738688/5707274949492736

Hi @Sanjay_Izardar

What do you mean by constructed completely? Volatile keyword is used to modify the value of a variable by different threads. It is also used to make class threads safe. It means that multiple threads can use a method and instance of the classes at the same time without any problem.