There were a variety of systems in use for onboard communication on military ships during the Second World War. Different systems were used by different navies, and not all systems would be available on all vessels.
On vessels in the US Navy, the shipboard general announcing system is known as the 1 Main Circuit or simply '1MC'. This was certainly in use during WW2, and its limitations were often mentioned in battle damage reports (as with, for example, the USS Franklin (CV-13)), together with recommendations for improvements.
Alarms like General Quarters would be sent over the 1MC circuit.
An improved version of the 1MC circuit (incorporating many of the recommendations for improvements from the War Damage Reports mentioned above) remains in use on US Navy vessels today.
Royal Navy aircraft carriers like HMS Victorious also had public address systems, as illustrated in this account of HMS Victorious' service with the US Navy in the Pacific.
Similarly, the accounts of survivors from the crew of the Bismarck indicate that the German Battleship also had a ship-wide public address system.
Hard wired sound-powered telephones were also in use on US Navy ships late in the war. These would enable communication with up to 20 stations simultaneously.
- US Navy sailor with sound powered telephone c1944; (Image source, Wikimedia)
Sound-powered telephones had been in-use on board naval vessels since at least the First World War. They had formed part of the Fire-control system on the Royal Navy's King George V-class battleship (1911), alongside the traditional voice-pipe communications.
The types and uses of battery- and sound-powered telephones in use by the Royal Navy are detailed in the Admiralty Fleet Orders, dated 9th July 1942 (section 3258).
The 'voice pipe', or 'speaking tube' had been in use since the early nineteenth century, and remains in use to this day. The example below is from the Second World War destroyer HMCS Haida:
And this example is on the bridge of the Second World War destroyer HMS Cavalier, now preserved at Chatham:
Communication between the ship's bridge and the engine room would be by means of the engine telegraph:
The example shown here is from the decommissioned tank landing ship, USS LST-325.
Even the ship's bell formed part of a ship's emergency alarm system in the US Navy during WW2. A 'low-tech' solution which, according to this article, would be used not only to warn of a fire on board, but also to give an idea of its location:
In the event of a fire, the bell is rung rapidly for at least five seconds, followed by one, two or three rings to indicate the location of a fire - Forward, amidships, or aft respectively.
Although the image accompanying that statement in the article shows the USS Bunker Hill (CV 17) on fire in 1945, I'd quesion how far the bell could be heard during an action at sea on such a large vessel. However, it might well be very effective on smaller vessels, and would have been better than nothing!