因为你的主函数main是静态的,它只能调用静态成员。

解决方案 »

  1.   

    JAVA中的程序都是类,要用成员函数就要产生对象,试问没有运行程序又如何产生对象。
    所以需要一个程序运行的入口,不产生对象就能运行的方法(静态方法)
      

  2.   

    那么以下的DateClass类中为什么不使用Static声明方法和变量呢?
    class DateClass {
     int month;
     int day;
     int year;
     public DateClass(int m, int d, int y) {
      month = m;
      day = d;
      year = y;
      // year = y + 1900;
     }
     public void display() {
      System.out.println(month + "/" + day + "/" + year);
     }
    }// Declare main program class
    class DateObject {
     public static void main(String args[]) {
      // Create and display a DateClass object
      DateClass birthday = new DateClass(7, 18, 64);
      birthday.display();
      // Create and display another DateClass object
      DateClass future = new DateClass(1, 1, 01);
    //  DateClass future = new DateClass(1, 1, 101);
      future.display();
     }
    }
      

  3.   

    My ICQ:348732090
    Yahoo:huangxinshui2002
    Mail box:[email protected],[email protected]
      

  4.   

    static所声明的方法和变量属于类,而不属于对象实体,以上程序的void main()属于class DateObject ,而DateClass中的方法和变量属于由class DateClass 产生的对象实体,所以不加static
      

  5.   

    static所声明的方法和变量属于类,叫类方法和类变量。
      

  6.   

    static方法不用生成实例就能通过类名调用,非static的方法得先有实例在通过实例调用方法