Forums Register Login

error: 'void' type not allowed here

+Pie Number of slices to send: Send
Hi! I'm new on the site and i'm studying with the Thinking in Java. I've a doubt with a program.

This work perfectly (is the solution of an exercisce):



This is my program:



It doesn't work.. the error is:

Testing.java:11: error: 'void' type not allowed here
System.out.println(Test.increment());


Why it doesn't work?
1
+Pie Number of slices to send: Send
System.out.println is used to print something out. But what are you trying to print? Your Test.increment() class returns void. If it could return something your code would be fine, but it can't print the absence of a value.

You'll note that in the original version it never tries to print the return value of the increment() method.
+Pie Number of slices to send: Send
Welcome to the ranch! You are at the right place to learn!
+Pie Number of slices to send: Send
 

Matthew Brown wrote:System.out.println is used to print something out. But what are you trying to print? Your Test.increment() class returns void. If it could return something your code would be fine, but it can't print the absence of a value.

You'll note that in the original version it never tries to print the return value of the increment() method.



Oh, it's true. Thanks for your help!

How can i multi-quote many replies?

@Joe Harry: Thanks, i like a lot this forum!
+Pie Number of slices to send: Send
 

Ivan Addeo wrote:How can i multi-quote many replies?


Use the methodology invented by the greatest inventor of all time. His name is Copy Paste.
So it takes a day for light to pass through this glass? So this was yesterday's tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2803 times.
Similar Threads
Just a doubt on static methods
Static vriables and Methods
Unary
When is a class loaded?
Static
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:25:45.