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