如题

解决方案 »

  1.   

    应该不行。main是程序的入口,它不属于任何类或对象。
      

  2.   


    package test;import java.lang.reflect.InvocationTargetException;
    import java.lang.reflect.Method;
    public class Main {    private static boolean isInvoked = false;    /**
         * @param args
         * @throws ClassNotFoundException 
         * @throws NoSuchMethodException 
         * @throws SecurityException 
         * @throws InvocationTargetException 
         * @throws IllegalAccessException 
         * @throws IllegalArgumentException 
         */
        public static void main(String[] args) throws 
            SecurityException, 
            NoSuchMethodException, 
            ClassNotFoundException, 
            IllegalArgumentException, 
            IllegalAccessException, 
            InvocationTargetException {
            Method mainMethod = Class.forName("test.Main").getMethod("main", new Class[]{String[].class});
            if (isInvoked) {
                System.out.println("isInvoked");
            } else {
                isInvoked = true;
                System.out.println("not isInvoked");
                mainMethod.invoke(null, new Object[]{args});
            }
        }}
      

  3.   

    应该没人去反射调用Main函数吧
      

  4.   


    import java.lang.reflect.Method;/**
     * Show loading a class and finding and calling its Main method.
     * 
     * @author Ian F. Darwin, http://www.darwinsys.com/
     * @version $Id: InvokeMain.java,v 1.3 2004/02/09 03:33:54 ian Exp $
     */
    public class InvokeMain {
      public static void main(String[] argv) {
        //+
        try {
          // First, find the class.
          Class c = Class.forName("InvokeMain"); // RECURSION
          System.out.println(c);      // Create the array of Argument Types
          Class[] argTypes = { argv.getClass(), // array is Object!
          };      // Now find the method
          Method m = c.getMethod("main", argTypes);
          System.out.println(m);      // Create the actual argument array
          Object passedArgv[] = { argv };      // Now invoke the method.
          m.invoke(null, passedArgv);    } catch (Exception e) {
          System.err.println(e);
        }
        //-
      }
    }
      

  5.   

    main函数也是一个函数。你写两个类,一个启动类A,执行A的main函数,在B中也存在main函数,只要参数符合,在A中执行B.main(参数)一定可以的。