就是写段完整程序,用到两个 static 的 method(除main()之外)
class SomeClass{
  static void m1(){//somecode}
  static void m2() {//somecode}
  m3(){}
 public static void main(String[] args)
  {//somecode}差不多吧

解决方案 »

  1.   

    哪位能详细的写1个例子。
    我手头没有材料。
    另外,static mathod 和 main method 区别在哪里?谢谢
      

  2.   

    static method就那些不需要申明就可以使用的方法。可以直接使用class.method()来调用。
    main method就是一个static 方法,因为main是java程序的入口函数,所以必须使用static方法。详细的例子很简单:public class  Test
    {
         public void static method1(String str){
             System.out.println("This is a test of method 1"+s);
         }     public void static method2(){
             System.out.println("This is a test of method 2");
         }     public void  method3(String str){//非static 方法
             System.out.println("This is a test of method 3"+s);
         }
    public static void main(String[] args) 
    {
                   Test t = new Test();
                   Test.method1("hello!");
          Test.method2();
                   t.method1("non static method");
    }
    }
      

  3.   

    static mathod 和 main method 区别是名字不同,
    main method在执行是回被首先调用
      

  4.   

    上面的那个只是一个示意性的代码,这个可以运行
    public class  Test
    {
         public static void  method1(String str){
             System.out.println("This is a test of method 1"+str);
         }     public static void  method2(){
             System.out.println("This is a test of method 2");
         }     public void  method3(String str){//非static 方法
             System.out.println("This is a test of method 3"+str);
         }
    public static void main(String[] args) 
    {
              Test t = new Test();
              Test.method1("hello!");
          Test.method2();
              t.method1("non static method");
    }
    }
      

  5.   

    static methods 是静态成员函数,被类的所有的实例所共享,独立于实例而存在,可以用类名称或实例名称来调用。
      

  6.   

    import javax.swing.*;public class D23StaticMethod{
    public static int readInt (String prompt){
    String inputString  = JOptionPane.showInputDialog(prompt);
    return Integer.parseInt (inputString);
    }
    //output method
    public static void output (String prompt){
    JOptionPane.showMessageDialog (null, prompt);
    System.out.println (prompt);
    }
    public static void main (String[] args){ //variables here int stuNum;
    int num;
    int tryAgain;
    int numberCount;
    final int LENGTH = 7;
    boolean keepGoing = true; while (keepGoing) {
    numberCount = 0;
    stuNum = readInt("Input your student #");
    num = readInt ("Input a digit from 1 - 9"); for (int i = 0; i<LENGTH; i++){
    if (stuNum % 10 == num)
    numberCount ++;
    stuNum = stuNum / 10; }
     //close for loop output("The number " + num +
    " appears " + numberCount + " time(s) in your student number"); tryAgain = readInt("Do you want to try again? (0 to quit)");
    if (tryAgain == 0)
    keepGoing = false; } //close while loop output ("Good-bye"); System.exit (0);
    }
    }