因为你的shape没有method()方法。我这么写:
package shape;
class Circle extends Shape{
 public void method(){
  System.out.println("circle");
 }
}
class Square extends Shape{
 public void method(){
  System.out.println("square");
 }
}
class Triangle extends Shape{
 public void method(){
  System.out.println("triangle");
 }
}
public class Shape{
  public void method() {
    System.out.println("Shape")
  }
  public static void main(String arg[]){
    Shape c=new Circle();
    Shape s=new Square();
    Shape t=new Triangle();  c.method();
  s.method();
  t.method();
 }

解决方案 »

  1.   

    不好意思,漏了个分号
    public class Shape{
      public void method() {
        System.out.println("Shape");
      }
      

  2.   

    Shape c=new Circle();
    你这里的Shape和Circle没有一点关系啊
    当然会报错了~~~~~
    是不是你的Circle有一个shape的接口阿还是circle就是直接继承了
    Shape啊?
      

  3.   

    上面那个(由陌生人修改后的程序)同下面这个有什么区别呢?我觉得应该是一样,都是upcast的程序吧?class Note {
      private int value;
      private Note(int val) { value = val; }
      public static final Note
        middleC = new Note(0), 
        cSharp = new Note(1),
        cFlat = new Note(2);
    } // Etc.class Instrument {
      public void play(Note n) {
        System.out.println("Instrument.play()");
      }
    }// Wind objects are instruments
    // because they have the same interface:
    class Wind extends Instrument {
      // Redefine interface method:
      public void play(Note n) {
        System.out.println("Wind.play()");
      }
    }public class Music {
      public static void tune(Instrument i) {
        // ...
        i.play(Note.middleC);
      }
      public static void main(String[] args) {
        Wind flute = new Wind();
        tune(flute); // Upcasting
      }
    }