By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

can we call main method from another main method

P: 5
how can we call one class main method from another class main method?
i tried but i got an idea for method we can call one method from another method
Sep 5 '07 #1
Share this Question
Share on Google+
2 Replies


madhoriya22
100+
P: 252
how can we call one class main method from another class main method?
Hi,
Plz make urself more clear. Why do you need that?
i tried but i got an idea for method we can call one method from another method
What do you mean by that line?
Sep 5 '07 #2

P: 17
how can we call one class main method from another class main method?
i tried but i got an idea for method we can call one method from another method
Try this ...
Expand|Select|Wrap|Line Numbers
  1. ClassB {
  2. public static void main(String[] args) {
  3.         System.out.println("ClassB main() Called");
  4. }
  5. }
  6.  
  7. ClassA {
  8. public static void main(String[] args) {
  9.                 System.out.println("ClassA main() Called");
  10.         ClassB.main(args);
  11. }
  12. }
  13.  
ouput
ClassA main() Called
ClassB main() Called

static methods are called without instantiating the object of class containing the method.
Sep 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.