Is it possible to set to null an instance of a class within the class?.
You cannot do this from member methods of the same instance. So this=null or something will fail.
How is it that the instance is set to null?
This question is wrong, we are setting references to null , but not to instances. Unused objects are automatically garbage collected in java.
If you set test=null , it will eventually receive garbage collection.
int main{ //Create a new test object Test test = new Test(); // use the object through test test=null; }
source share