本帖最后由 Tinck 于 2014-5-10 13:01 编辑
- abstract class dongwu
- {
- abstract void chi();
- }
- class mao extends dongwu
- {
- public void chi()
- {
- System.out.println("chiyu");
- }
- public void zhualaoshu()
- {
- System.out.println("zhualaoshu");
- }
- }
- class gou extends dongwu
- {
- public void chi()
- {
- System.out.println("kengutou");
- }
- public void kanjia()
- {
- System.out.println("kanjia");
- }
- }
- class zhu extends dongwu
- {
- public void chi()
- {
- System.out.println("chishiliao");
- }
- public void beichi()
- {
- System.out.println("beichi");
- }
- }
- class duotai
- {
- public static void main(String[] args)
- {
- show(new mao());
- }
- public static void show(dongwu d)
- {
- d.chi();
- mao m=(mao)d;
- m.zhualaoshu();
- }
- }
复制代码
为什么在show里面mao m=new mao();
m.zhualaoshu();
会出现无法从静态中引用非静态方法,而转换后却不会 |