Calling a class from another class with main method

dorothy

In Java, can we call a main() method from another class? For example, ClassA is meant to be run on the command line as it has a main(String[] args) method defined.

I want to call this ClassA inside ClassB. Do I initialize a new object of the class, like

ClassA newobject = new ClassA()

or is there a way to pass the command line options of ClassA inside ClassB.

thanks

Mike Thomsen
A.main(...string args here);

That's all there is to it because it's just a simple static void method. Fair bit of warning, it will be run in the same process and probably thread too as the caller. If what you are looking for is to have it run it as a real, honest to goodness different program then you'll need to use the Java Process API to actually spawn a proper new JVM. You can probably get away with this for a lot of things small programs:

Runnable r = new Runnable() {
    public void run() {
        A.main(argsArray);
    }
};

Thread t = new Thread(r);
t.start();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a method from one class in another class

From Dev

Calling Main Method in Java Class From JSP

From Dev

Implicitly calling a method in a class from main

From Dev

Calling a default method from Interface in Main Class

From Java

Calling method of Another class from run() method

From Javascript

Calling a method from another method in the same class

From Dev

Call from a main of one class, a main method of another class

From Dev

Calling a method from inside of another class

From Dev

Calling a method of the MainActivity from another class?

From Dev

Calling method from another class unsuccessful

From Java

java calling a method from another class

From Java

Calling service method from another service class

From Java

NullPointerException when calling method from another class

From Dev

JGroups RpcDispatcher calling method from another class

From Dev

calling render method from another class

From Dev

calling method in mainactivity from another class in android

From Dev

Python: Calling a decorator method from another class

From Dev

Having trouble calling a method from another class

From Dev

Syntax Error in Calling a method from another class

From Dev

calling a boolean method from another class

From Dev

Calling a method from another class in broadcast receiver

From Dev

Calling a method from another class that removes views

From Dev

Calling StartActivity(intent) method from another class

From Dev

python, calling a method from another class

From Java

calling String method from different class to main class

From Dev

Calling a parametrized method from LibraryCollection class to main Class

From Dev

Calling a class method from another class method in Python 2.7

From Dev

Calling array method in main class

From Dev

Django - Calling one class method from another in Class Based View

Related Related

  1. 1

    Calling a method from one class in another class

  2. 2

    Calling Main Method in Java Class From JSP

  3. 3

    Implicitly calling a method in a class from main

  4. 4

    Calling a default method from Interface in Main Class

  5. 5

    Calling method of Another class from run() method

  6. 6

    Calling a method from another method in the same class

  7. 7

    Call from a main of one class, a main method of another class

  8. 8

    Calling a method from inside of another class

  9. 9

    Calling a method of the MainActivity from another class?

  10. 10

    Calling method from another class unsuccessful

  11. 11

    java calling a method from another class

  12. 12

    Calling service method from another service class

  13. 13

    NullPointerException when calling method from another class

  14. 14

    JGroups RpcDispatcher calling method from another class

  15. 15

    calling render method from another class

  16. 16

    calling method in mainactivity from another class in android

  17. 17

    Python: Calling a decorator method from another class

  18. 18

    Having trouble calling a method from another class

  19. 19

    Syntax Error in Calling a method from another class

  20. 20

    calling a boolean method from another class

  21. 21

    Calling a method from another class in broadcast receiver

  22. 22

    Calling a method from another class that removes views

  23. 23

    Calling StartActivity(intent) method from another class

  24. 24

    python, calling a method from another class

  25. 25

    calling String method from different class to main class

  26. 26

    Calling a parametrized method from LibraryCollection class to main Class

  27. 27

    Calling a class method from another class method in Python 2.7

  28. 28

    Calling array method in main class

  29. 29

    Django - Calling one class method from another in Class Based View

HotTag

Archive