Unlike gas water heaters that have gas burners to heat the water, electric water heaters rely upon an upper and lower pair of metal heating elements. These heating elements are made of metal and get hot from electrical resistance, similar to what you would find in an electric cooking range.
In a water heater the cold incoming water is not delivered at the top of the tank, but rather near the bottom through a dip tube as seen in the diagram Anatomy of a Water Heater.
As a result of a cold water supply coming in near the bottom of the tank, the lower heating element is the workhorse of the electric water heater. The upper heating element really only contributes when there is a high hot water demand and only serves to heat water in the upper portion of the tank. A constant supply of lukewarm water during a shower is indicative of a defective upper heating element. Short duration hot water supply during a shower is indicative of a defective lower heating element. Replacement heating elements must be of the same style and voltage/wattage rating as the ones presently in the water heater.