aspose file tools*
The moose likes Beginning Java and the fly likes Static Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static Methods" Watch "Static Methods" New topic
Author

Static Methods

Theresa Marlin
Ranch Hand

Joined: Sep 23, 2009
Posts: 49
I had an original code:

I was then supposed to change Triangle to a static method and delete the class TriangleCalc. What is a static method and how do they work? I tried what I could do (below), and got an error. I am unsure of how to include a static method in a main method. Here's my code:


Thank you!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

A static method is a method defined with the "static" keyword.

You say you "got an error", but neglected to provide any information about the error.
Theresa Marlin
Ranch Hand

Joined: Sep 23, 2009
Posts: 49
Sorry about that, I tend to ask for help without providing critical information :P One error says illegal start of expression. Another says need a semi colon. Why would I ever need a semi colon between two brackets?



Thanks!!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're trying to create a method smack-dab in the middle of another method--that's not legal Java.
Theresa Marlin
Ranch Hand

Joined: Sep 23, 2009
Posts: 49
The assignment said not to delete the class from the first assignment- should I just create another class?

Thanks,
Theresa
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

See how main is declared? Main is a static method. How might you declare your own static method?
Theresa Marlin
Ranch Hand

Joined: Sep 23, 2009
Posts: 49
by creating another static main method, and putting the class there?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Nope. Maybe check out some Java tutorials--all you're doing is creating a new method and removing the Triangle class. You might be overthinking this.
Theresa Marlin
Ranch Hand

Joined: Sep 23, 2009
Posts: 49
Alright, I will, thanks! Do you have any tutorials to recommend for static?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not really.

As I said: main is already a static method. In other words, why would creating a new static method look any different than the main method???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static Methods