• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Return type void..

 
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a problem understanding the void keyword. Is there a simple definition for this? Its probably a simple one, but its eluding me at this moment.
Thanks
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means that the method does not return anything to the caller.
For instance I can make a class test:

myInt is now holding 182 because the method returned that value.
If I said
public void whatever(){ //do stuff }
When I call this method it does NOT send back a value.

[This message has been edited by Cindy Glass (edited February 26, 2001).]
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A void return type means that there is nothing returned.
A function with a return type of "void" would do its processing and then either just issue a "return;" statement, or fall out of the bottom of the function and return to where it was called from.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int methodName() is expecting to return an integer value.
double methodName() is expecting to return a double.
void methodName() is not expecting to, nor will it let you, return anything.
Say you have a method that you want to print a value to the screen, or print out a record, you could use a void method with no return because it is all being done within that method. If you are using another method to do some action and are passing it a value from this method, you have to show the return type as part of your method( int, double, String, etc ).
I hope this has helped and not confused.
 
Andy Ceponis
Ranch Hand
Posts: 782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup that helped alot. Thanks for the replies. For some reason it is usually a lot easier to understand what other "real" people have to say on subjects rahter than to try and figure out what some books have to say about it when your confused.
Thanks
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's why we ALL hang out here
 
30 seconds to difuse a loaf of bread ... here, use this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic