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 public static void, public void and public 'returnType' Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "public static void, public void and public Watch "public static void, public void and public New topic
Author

public static void, public void and public 'returnType'

ashlan cooper
Greenhorn

Joined: Nov 23, 2010
Posts: 11
can someone please explain when can I use those above. I get confused.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If the method is returning something, then the return type needs to be specified. Otherwise, "void" needs to be specified to indicate that nothing is returned.

If the method should be associated with the class (instead of a particular instance of the class), then the keyword "static" is used. Without "static," the method is an "instance" method. See Java Tutorial.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
public static void = a static method which allows public access and returns nothing. This means it is available for anyone to see/use because it is public, it is associated with the class not an instance because it is static, and void always simply means there is no return value for the method.

public void = a non-static method which allows public access and again returns nothing. This means it is available to anyone just as above, but this time because it is not static it is associated with an instance not the class itself. Again because of the void there is no return type.

public 'returnType' = a public method which is showing you that where "returnType" is you may place whatever it is your would like your method to return. If you want it to return a string a method would look like


or if you wanted to return an Integer


Generally it is a good practice to search for the information on your own first prior to posting as each of these come up with tons of information if Googled. Also check out the link in marc's post. Welcome to the Ranch!


Everyday in every way, we get a little better.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: public static void, public void and public 'returnType'
 
Similar Threads
Listener
main
Version conflict
about { } notation
help me understand a exam in 《Java Threads Third Edition》