Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

static vs. non static

800326Mar 4 2009 — edited Mar 6 2009
I'm writing a standalone java application. in main method, I need to call a method in another class like"

{code}pulic static void main(){
AClass.call();
}{code}
or
{code}pulic static void main(){
AClass a = new AClass();
a.call();
}{code}
should I make call() in AClass static?

in my situation, there is only one AClass instance needed here, but I do not need to restrict that there is only 1 instance of AClass cross whole application -- this is not required.

So, seems making call() static or non-static, both should work in this situation.

Is there any suggestion what would be good? static vs. non static ?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 3 2009
Added on Mar 4 2009
15 comments
435 views