Forums Register Login

void

+Pie Number of slices to send: Send
Hello all members,

I am new to java programming.

i know that constructor can't return any value not even void.

what does it mean ???
Can you tell me the difference between "void" and no return value.

Please help.

Thanks in advance.
+Pie Number of slices to send: Send

you cannot represent 'void' it is just a keyword in the java language

a method with void in its declartion does not return a 'void' it returns nothing
+Pie Number of slices to send: Send
All methods must have a return type. I believe that "void" is just to allow the compiler know that a particular method will have a return type of nothing aka will not return any data. A constructor on the other hand is not a method, even though they are similar... therefor you can't declare one as having a return type, including void. The compiler already knows what a constructor does so it does not need void added.

That's my understanding on it anyways.
+Pie Number of slices to send: Send
 

Brian Legg wrote:All methods must have a return type. I believe that "void" is just to allow the compiler know that a particular method will have a return type of nothing aka will not return any data. A constructor on the other hand is not a method, even though they are similar... therefor you can't declare one as having a return type, including void. The compiler already knows what a constructor does so it does not need void added.

That's my understanding on it anyways.


In fact, if you add void to a constructor, it becomes an ordinary method - that just happens to have the same name as the class:
+Pie Number of slices to send: Send
I completely forgot about that Rob. Funny how many things are allowed in programming languages which are terrible ideas
+Pie Number of slices to send: Send
 

Rob Prime wrote:

Brian Legg wrote:All methods must have a return type. I believe that "void" is just to allow the compiler know that a particular method will have a return type of nothing aka will not return any data. A constructor on the other hand is not a method, even though they are similar... therefor you can't declare one as having a return type, including void. The compiler already knows what a constructor does so it does not need void added.

That's my understanding on it anyways.


In fact, if you add void to a constructor, it becomes an ordinary method - that just happens to have the same name as the class:




Thanks a lot Rob.
It wasn't my idea to go to some crazy nightclub in the middle of nowhere. I just wanted to stay home and cuddle with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 834 times.
Similar Threads
modifier such as void ?
Recursion: returning a value/not returning a value(void)
cast code so that i could receive the amount being returned from a method?
just check this...
SCJP : query regarding increment/decrement operator.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:36:01.