Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where should i call method main

 
shashi sarle
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Balu...
so i assume i can declare in any of the class...
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic