Question

Why do you need to add the keyword void before certain methods. I know it means the method returns nothing (or at least that's what I think it means), but why should you add void even if you already know the method is supposed to return nothing?

Was it helpful?

Solution

To tell the compiler that the method is supposed to return nothing.

This kind of redundancy allows the compiler to tell you if you make a mistake somewhere.
(eg, forgetting a return statement)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top