Home > Back-end >  Consult, whether the object to null himself by yourself?
Consult, whether the object to null himself by yourself?

Time:10-13

 public class A {
The static B B=new B ();

Public static void main (String [] args) {
//B type from A class - this class instantiation object is set to null, this is no problem,
B=null;

//but the object b can be set to null himself?
B.s etNull ();
}
}


 public class B {
Void setNull () {
/*
It is no good, I was meant to B type instantiation objects,
Call this method, set themselves to null, whether can you?
*/
This=null;
}
}

CodePudding user response:

From the above example, an object seems to be no way to yourself is set to null, only can let others (other) to set himself to null,