GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  Java
Go To First  |  Previous Question  |  Next Question 
 Java  |  Question 3 of 928    Print  
Can a main() method of class be invoked in another class

  
Total Answers and Comments: 17 Last Update: November 15, 2006   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: kmhariharan
 

It is possible.we can easily invoke a main() of a class from another class.

I show  u demo here.

//Class Test

public class Test

{

public static void main(String args[]) //Main Method which is

//Invoked by another class Testing

{

System.out.println("Test Class main() Method is Called");

}

}

//Class Testing

public class Testing

{

public static void main(String args[])

{

if (args.length!=0)

{

Test.main(args);// Main method of Test Class is Calling

}

}

}



Above answer was rated as good by the following members:
Krishna Jeevan
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
June 29, 2005 04:16:42   #1  
ravish        

RE: Can a main() method of class be invoked in another class
yes if the main() is declared as public.
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
July 07, 2005 08:04:42   #2  
Panchal Rajendra S        

RE: Can a main() method of class be invoked in another class
yes because it need not be instantiated.
 
Is this answer useful? Yes | No
July 24, 2005 11:26:32   #3  
Hariharan        

RE: Can a main() method of class be invoked in another class
no we can't do
 
Is this answer useful? Yes | No
August 03, 2005 02:54:52   #4  
Narasimha Chary        

RE: Can a main() method of class be invoked in another class
Yes it is possible
 
Is this answer useful? Yes | No
August 03, 2005 08:44:16   #5  
Sandip Gupta        

RE: Can a main() method of class be invoked in another class
yes if that is not inistantiated.
 
Is this answer useful? Yes | No
August 24, 2005 03:17:10   #6  
raghu        

RE: Can a main() method of class be invoked in another class
yes main is allso method we can call them in any class only within the static context

 
Is this answer useful? Yes | No
September 01, 2005 02:29:18   #7  
sandeep patil        

RE: Can a main() method of class be invoked in another class
Yes It can be
 
Is this answer useful? Yes | No
September 11, 2005 03:43:16   #8  
varadharajulu        

RE: answer
yes
 
Is this answer useful? Yes | No
September 12, 2005 07:11:51   #9  
D.S.Reddy        

RE: Can a main() method of class be invoked in another class
Yes its possible but only if the class in which the main() is defined must be Public.
 
Is this answer useful? Yes | No
September 13, 2005 08:19:41   #10  
kmhariharan Member Since: September 2005   Contribution: 4    

RE: Can a main() method of class be invoked in another...

It is possible.we can easily invoke a main() of a class from another class.

I show u demo here.

//Class Test

public class Test

{

public static void main(String args[]) //Main Method which is

//Invoked by another class Testing

{

System.out.println( Test Class main() Method is Called );

}

}

//Class Testing

public class Testing

{

public static void main(String args[])

{

if (args.length! 0)

{

Test.main(args);// Main method of Test Class is Calling

}

}

}


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape