What happens when an object is assigned to another object
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: public class DrumKitTestDrive { /** * @param args */ public static void main ( String [] args ) { // TODO Auto-generated method stub Echo e1 = new Echo (); Echo e2 = new Echo (); // **e2 = e1;** int x = 0 ; while ( x < 4 ){ e1 . hello (); e1 . count = e1 . count + 1 ; if ( x == 3 ){ e2 . count = e2 . count + 1 ; } if ( x > 0 ){ e2 . count = e2 . count + e1 . count ; } x = x + 1 ; } System . out . print ( e2 . count ); } } class Echo { int count = 0 ; void hello (){ System . out . println ( "Hellooooo...." ); } } The output of this