實例化問題
視頻中用的實例化是
Telphone tel1 = new CellPhone();
Telphone tel2 = new SmartPhone();
為啥不直接直接使用
CellPhone()?tel1 = new CellPhone();
SmartPhone tel2 = new SmartPhone();
?????
視頻中用的實例化是
Telphone tel1 = new CellPhone();
Telphone tel2 = new SmartPhone();
為啥不直接直接使用
CellPhone()?tel1 = new CellPhone();
SmartPhone tel2 = new SmartPhone();
?????
2018-08-14
舉報
2018-08-14
public static void main(String[] args) {
//使用父類human來創(chuàng)建Chinese對象,(多態(tài)方法)
human ch1 = new Chinese();
ch1.say();
//使用本類Chinese來創(chuàng)建Chinese對象
Chinese ch = new Chinese();
ch.say();
}
2018-08-14
Telphone是父類,父類Telphone可以對子類CellPhone進行對象創(chuàng)立,這是多態(tài)的方法,同時你第二種方法也是正確的,畢竟我們學習,多學點創(chuàng)建對象的方法也是可以的。