File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes where should i call method main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "where should i call method main" Watch "where should i call method main" New topic
Author

where should i call method main

shashi sarle
Greenhorn

Joined: Oct 15, 2008
Posts: 12
Hi Friends please suggest...........

class A
{
public void aMethod() {}
}

class B extends A
{
public void aMethod() {}
}

class C extends B
{
public void aMethod() {}
}


which class should i call method main()
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

which class should i call method main()


I suppose , you mean declare main method. It depends entirely on which class you want to expose to outside world.
shashi sarle
Greenhorn

Joined: Oct 15, 2008
Posts: 12
Thanks Balu...
so i assume i can declare in any of the class...
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

Welcome.

Yes for the standalone applications , the more cleaner way would be declaring the main method in a separate class. But from the example(incomplete) that you have shared all looks similar and very well you can declare in any of the classes
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

You can place the main() method in any of the classes namely A,B,C. While compiling you can give the name of the source code file i.e the name you used to save the application using javac and when you execute the application use the class name in which you have defined the main method e.g java C (where C is the class you have defined the main method).

Hope this helps.


Regards, Sud.
SCJP 5 ScjpFAQ JLS
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Agree with Balu Sadhasivam. Get into the habit of creating a XXXDemo class with a main method in, and start your application from a different class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: where should i call method main