抽象類不能直接創(chuàng)建,可以定義引用變量。這句話具體是什么意思呢?
qq_不睡覺的怪叔叔_0
2016-05-07 16:40:42
TA貢獻(xiàn)223條經(jīng)驗(yàn) 獲得超56個(gè)贊
//抽象的person public?abstract?class?Person?{ public?abstract?void?say();//抽象方法 } public?class?Son?extends?Person?{ @Override public?void?say()?{ System.out.println("........"); } } public?class?Demo{ ????public?static?void?main(String[]args)throws?Exception{ ????????Person?p=null;//引用變量p ????????p?=new?Son();//任何累繼承了Person都可以來實(shí)例化 ????} }
舉報(bào)