Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

basic question open a class from a class

Status
Not open for further replies.

welshone

Programmer
Jul 30, 2001
414
GB
hello,
How can I do this, its starting to do my head in !

I have one class called test with a main method.

I have another class called testing with a main method.

how can I run the testing class main method from the test class method ?


this shpould be easy, yeah ?
 
you can only have one static main method in a program. You can have multiple classes though.

public class Testing{
public void testMe(){ }
}

public class Test{

public static void main (String [] args){

Testing t = new Testing();
t.testMe();
}
}

~za~
You can't bring back a dead thread!
 
Simple : just call the main method :
Code:
    StringExample ex = new StringExample();
    ex.main(args);
Or
Code:
    StringExample.main(args);
 
"Under certain conditions" the following is true : You can have multiple classes in 1 source file and in everyone of those classes you can have a "static main" and you can call these main methods.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top