The U.S. Pacific Fleet commander said Thursday he would launch a nuclear strike against China next week if President Donald Trump ordered it, and warned against the military ever shifting its allegiance from its commander in chief.

Adm. Scott Swift was responding to a hypothetical question at an Australian National University security conference following a major joint U.S.- Australian military exercise off the Australian coast. The drills were monitored by a Chinese intelligence-gathering ship off northeast Australia.

Asked by an academic in the audience whether he would make a nuclear attack on China next week if Trump ordered it, Swift replied: "The answer would be: Yes."

"Every member of the U.S. military has sworn an oath to defend the constitution of the United States against all enemies foreign and domestic and to obey the officers and the president of the United States as commander and chief appointed over us," Swift said.

He added: "This is core to the American democracy and any time you have a military that is moving away from a focus and an allegiance to civilian control, then we really have a significant problem."

Pacific Fleet spokesman Capt. Charlie Brown later said Swift's answer reaffirmed the principle of civilian control over the military.

"The admiral was not addressing the premise of the question, he was addressing the principle of civilian authority of the military," Brown said. "The premise of the question was ridiculous."

The biennial Talisman Saber exercise involved 36 warships including the aircraft carrier USS Ronald Reagan, 220 aircraft and 33,000 military personnel.

It was monitored by a Chinese People's Liberation Army-Navy Type 815 Dongdiao-class auxiliary general intelligence vessel from within Australia's 200-mile exclusive economic zone.

Swift said China had similarly sent an intelligence ship into the U.S. exclusive economic zone around Hawaii during the Pacific Fleet-hosted multinational naval exercise in 2014.

China had a legal right to enter the American economic zone for military purposes under the United Nations Convention on the Law of the Sea — or UNCLOS— which defines the rights and responsibilities of nations sailing the world's oceans, he said.

Governments needed to engage with Beijing to understand why the Chinese did not accept that the United States had the same access rights within China's exclusive economic zone, Swift said.

"The dichotomy in my mind is why is there a different rules-set applied with respect to taking advantage of UNCLOS in other EEZs, but there's this perspective that there's a different rules-set that applies within another nation's (China's) EEZ? " Swift said.