典型的多态应用,Instrument可以有好几种形式,其中一种就是wind.
面向对象的三大优点之一,你应该多多实践,才能体会其中的妙处!

解决方案 »

  1.   

    但为什么是Instrument.tune(flute);
             而不是flute.play();
             flute.play();也是多态的应用呀!当flute赋予instrument类型的对象变量时也是一个多态应用,为什么非要用static tune()呢?
      

  2.   

    我不知道你学过接口了没,当你会使用接口之后,你就明白了。
    你写个rmi程序,就会发现全是这样的例子。当然:
            Instrument.tune(flute);
             而不是flute.play();
    知识在这儿强调那个例子而已,并没有实际的用处。
    使用static tune(),可以不用实例化Instrument对象呀!!!
      

  3.   

    可你已经实例化一个flute了,只写flute.play()就好了,为什么要写instrument.tune(flute)呢,不是很麻烦吗?
      

  4.   

    我觉得这种基础性的书籍中讲的例子都是为了说明用法,而不是说明用了有什么好处,好处需要要实际编程中来琢磨的上面的例子一个比较明显的好处是:Instrument可以对所以的Instrument对象进行统一控制
    flute.play()的话控制就分散了,不便于对象的管理
      

  5.   

    好比说Instrument有好几个子类:dog,cat,pig,wind
    有一个Instrument[]类型数组叫ArrayALL,里面有很多这些子类的对象(混在一起)我也只是写出
                for(int i=0;i<ArrayALL.length;i++)ArrayALL[i].play();
    就可以访问了
    没必要写
                for(int i=0;i<ArrayALL.length;i++)Instrument.tune(ArrayALL[i]);
    而且,这样写也不那么易读易用吧?
      

  6.   

    假如public void tune(Instrument i){
       System.out.println("Before playing "+i);
       i.play();
       System.out.println("After playing "+i);
    }你就该知道为什么要tune而不是直接play