It certainly can, but whilst heating to the high temperatures required, the efficiency reduces. However, even low efficiencies are far better than an electric immersion heater. Most of the latest heat pump units have the hot water function built in, so it is usual to use this facility.
As the insulation levels in buildings increases, the room-heating demand drops, but the hot water demand is, if anything, increasing. It is therefore becoming more important to optimise the hot water facility. i.e. the size and design of the hot water cylinder is very important.