Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how can I?  RSS feed

 
Suhas Madap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
how can i return something from a void method. I know that we cannot return. But still is there any possiblity.If so please it would be great if some one explain in detail.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you change the return type ?
If you explain what you are trying to do, we may be better able to help you.
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Suhas Madap:
Hi,
how can i return something from a void method. I know that we cannot return. But still is there any possiblity.If so please it would be great if some one explain in detail.


Dear Suhas,

You can use an Object in a method like below one..



The output of this program is:

Before Call.i: 0
Before Call.str: Java
After Call.i: 10
After Call.str: Ranch


Hope this will help your understanding
 
Pratibha Malhotra
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i return something from a void method. I know that we cannot return. But still is there any possiblity.If so please it would be great if some one explain in detail.


You can surely not return anything with void.
You can however set value you want to return in an instance/static variable and then can access same outside your method.
 
Suhas Madap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every one,
thank you, very much for your valuable suggestion.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!