The Duke of Cambridge has downed a tot of rum in a ritual for newly qualified submariners as he attended the rededication ceremony of the only surviving British Second World War-era submarine.

In his role as Commodore-in-Chief, Submarines, William visited HMS Alliance at the Royal Navy Submarine Museum in Gosport, Hampshire, which has been restored at a cost of £7 million.

The Prince is the royal patron of the conservation appeal which enabled the repairs and refurbishment of the submarine, which reopened to the public last month.

William arrived by Lynx helicopter and was greeted by the cheers of local schoolchildren waving Union flags.

He then attended a service led by Royal Navy chaplain Reverend Ernie Grimshaw to rededicate the submarine, as well as to remember two Australian First World War-era submarines, one of which, AE1, sank in 1914 off Papua New Guinea and the other, AE2, was scuttled off Turkey and the crew seized.

Daily Echo:

Mr Grimshaw said: ''I have served on submarines and to see the commitment, dedication and professionalism of submariners is something to behold and it's right to remember them today.''

When asked by guide Terry Fearnley, a former stoker on Alliance, if he would be bringing son George to see the submarine, William replied: ''It's great that younger generations can really see and feel what it is like to be a submariner. I wouldn't let George in here. A nightmare George is - too many things for him to pull and hit.''

Mr Fearnley said he should not worry, to which the Prince replied jokingly: ''You say that.''

Vice Admiral Sir Tim McClement, chairman of the museum, said: ''Your Royal Highness, thank you very much for helping us by coming back to the Royal Navy Submarine Museum. Since your last visit five years ago, I think you will have noticed some changes.

''She is the only World War Two-era UK ocean-going submarine open to visitors. Laid down in 1944, she completed 26 years operational service in the Far East and Cold War and for the last 30 years she has been the centrepiece of our museum, but she has suffered terribly from a lot of corrosion.

''Your Royal Highness very kindly accepted, at our request, to be our patron for our appeal and because of the huge generosity of so many, in October 2011 we started our work. Two and a half years later, it's all done.''

Following the service, the Last Post was played before the Prince presented prizes to pupils from Brune Park Community School who took part in a poetry competition about the submarine. The winner, 12-year-old Alegria Tracey then read her poem to the audience.

The Prince was given a tour of the submarine and as he left the vessel, he drank the tot of rum and was presented with the Dolphins badge which is given to submariners as they are given their first posting.

The moment was greeted with a countdown and cheers from the crowd of guests, many of whom were former submariners.

As he returned to the museum, the Prince said: ''Where's everyone else's rum?''

Bill Sainsbury, marketing manager for the museum, prepared the drink, which was Pusser's Navy Rum, for the Prince and said he seemed to enjoy it.

Ms Sainsbury said: ''He really enjoyed it, he seemed to be happy to have his rum, it put a big smile on his face.

''I had to prepare a gulper's measure for him, which is more than a sip. It was not watered down, the tradition is that lower ranks have it watered down and the officers have less water. His was neat, I didn't put any water in it which is right for his rank. I didn't measure it but he definitely had a good gulp.''

Daily Echo:

Newly qualified submariners are presented with the badge featuring two gold dolphins in the glass of rum which they drink and have to catch the badge in their teeth, although the Prince was given his badge without having to perform the trick.

Ms Sainsbury added that Sir Tim, who presented the rum and the badge to the Prince, told him they had decided not to put the badge in the rum because they did not want to risk choking him.

HMS Alliance was designed for service in the Far East and was launched in 1947 and completed a distinguished 26-year career during the Cold War until it was retired and became the centrepiece of the submarine museum.

Daily Echo:

Moored on the museum quayside since 1981, the submarine became a rusted wreck and the restoration programme, partly funded with a £3.4 million grant from the Heritage Lottery Fund, returned it to a shining example of 20th century engineering.

The project to restore HMS Alliance has also included a new education and volunteering programme.

More than 100 volunteers from the local area have contributed by undertaking duties at special fundraising events, helping conserve the submarine and working behind the scenes in the archives.