| |
GeekInterview.com > Interview Questions > J2EE > Core Java
| Print | |
Question: Can we declare multiple main() methods in multiple classes.ie can we have each main method in its class in our program?
|
| May 05, 2007 08:13:31 |
#9 |
| rameshvdnv |
Member Since: December 2006 Total Comments: 11 |
RE: can we declare multiple main() methods in multiple... |
Yes, we can have multiple main()'s in a java application.And we can call a main() of one class to main()of another class.Here is the Eg: class Test{ public static void main(String[] args)throws Exception{ for(int i=0;i<args.length;i++){ System.out.println(s); } } class Arr{ public static void main(String[] args)throws Exception{ String s[]={"Xyz","lkm","abc"}; Test.main(s); } } |
| |
Back To Question | |