Can I replace a 30A breaker with a 40A breaker for a new water heater?
Your current 30A water heater circuit was probably wired with #10 solid copper. You can confirm this by inspecting the stamp or printing on the cable jacket, or by using a gauge measuring tool (with the power safely disconnected). 

A 40A circuit typically calls for #8 copper wire, which is usually stranded. It's a markedly larger cable bundle. If you don't have that, DO NOT increase the breaker size. A circuit breaker's primary function is to protect wiring from overload, and a 40A breaker does not adequately protect #10 wire.

This is standard advice and doesn't apply to inordinately long runs or other nonstandard scenarios which may call for even larger wire.