Public classbeiming {/** * @paramif an instance of a class is directly connected by an equal sign, then two instances point to the same object.
* This way they call the property, or the method will always point to the left instance. The change will fail.
*
* The workaround is to call the property when the attribute is equal and then connect it with an equal sign so that the above behavior does not occur.
* See examples
*/
floatTom;
Public Static voidMain (string[] args) {beiming B1=Newbeiming (); Beiming B2=Newbeiming (); B1.tom= (float) 12.00; B2.tom= (float) 345.00; System.out.println ("b1:tom=" +b1.tom+ "\ n" + "b2:tom=" +b2.tom); //B1 = B2; B1.tom=b2.tom;//Solution System.out.println ("b1:tom=" +b1.tom+ "\ n" + "b2:tom=" +b2.tom); B2.tom= (float) 34355.00; System.out.println ("b1:tom=" +b1.tom+ "\ n" + "b2:tom=" +b2.tom); }}
Aliasing occurs when an object is passed into a method
Public classbeiming {Static voidf (letter Y) {//creates a new static method that assigns the properties of the passed-in objectY.woca = "Static"; } Public Static voidMain (string[] args) {Letter L=NewLetter ();//Create a new objectL.woca = "Woca attribute of the newly added instance";//assigns a value to the object.System.out.println (the content of the Woca property is: "+L.woca); F (l); //call the method, put in the new object, and then output, it will be found that the reference point has changed, this need to avoid the main.System.out.println (L.woca); }}classletter{//new class for beiming class testsString Woca;}
Alias Behavior in Java