Java provides a main method that invokes another class in the main method of a class

Source: Internet
Author: User
In Java, there are two ways in which a class can invoke another class by instantiating the class, invoking the method of instantiating the object, and invoking it using the Java mapping mechanism. The first method is no longer explained, and the second method uses the following:

public class Run {

public static void Main (string[] args) {
String str = args[0] + "Hello World";
System.out.println (str);
}

}

Import Java.lang.reflect.Method;

public class Jobrun {
public static void Main (string[] args) {
String idstr = "YAya";
try {
Method method = Run.class.getMethod ("main", String[].class);
Method.invoke (Run.class.newInstance (), New object[]{New String[]{idstr});
catch (Exception e) {
E.printstacktrace ();
}

}
}

Http://blog.sina.com.cn/s/blog_6035d1770100gsmm.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.