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.
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.
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: