為什么console = new Scanner(System.in);要放在構(gòu)造方法里呢?
我直接private Scanner?console = new Scanner(System.in);不是有也可以嗎?為什么console = new Scanner(System.in);要放在構(gòu)造方法里呢?
我直接private Scanner?console = new Scanner(System.in);不是有也可以嗎?為什么console = new Scanner(System.in);要放在構(gòu)造方法里呢?
2017-07-18
舉報(bào)
2017-07-18
因?yàn)閷?shí)例化對(duì)象的時(shí)候會(huì)執(zhí)行構(gòu)造方法,這樣更方便不用寫單獨(dú)的代碼了。