HONG KONG — The commander of the United States Pacific Fleet was asked a hypothetical question during a talk on Thursday in Australia: If President Trump ordered a nuclear strike on China, would he comply?

“The answer would be yes,” the commander, Adm. Scott H. Swift, replied.

Admiral Swift, who was speaking at Australian National University in Canberra, said his answer was a reflection of the principle of civilian control over the military.

“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 the commander in chief appointed over us,” he said.

Capt. Charlie Brown, a spokesman for the United States Pacific Fleet, said the premise of the question about using nuclear weapons against China was “ridiculous,” and not something Admiral Swift had raised himself.

“Perhaps he more forcefully could have refuted the hypothetical,” Captain Brown said. “He was trying to find an opportunity to use it to deliver a message on something positive, and that was the answer he gave on civilian control.”

There was no immediate official response from China to the admiral’s comments.

Rory Medcalf, the head of the National Security College and host of the talk, said the question had been posed to Admiral Swift without much context and had put him on the spot.

“Admiral Swift answered the question the only way a serving military officer could,” Mr. Medcalf said. “It would have been a lot more controversial if he had said no, he would not obey the commander in chief.”

Admiral Swift’s remarks in Canberra focused on the role of the armed forces in ensuring stability and a rules-based system of international relations. He spoke after war games conducted by more than 30,000 military personnel from Australia and the United States took place off the coast of Queensland and the Northern Territory of Australia. A Chinese Navy spy ship was operating nearby while the operations, known as the Talisman Saber exercises, were underway in the Coral Sea, the Australian military said.

China maintains a smaller nuclear arsenal than the United States or Russia, and has long said that it would not use nuclear weapons against a nation that did not have them or in a first strike against a nuclear-armed adversary. But there have been occasional calls to change that “no first use” policy. In 2005, a Chinese military official told a group of foreign reporters that Beijing should consider using nuclear weapons against the United States if it intervened in a conflict over Taiwan, the self-ruled island China considers part of its own territory.

In addition to Taiwan, there are plenty of potential flash points in the relationship between the United States and China. On Sunday, a United States Navy spy plane took evasive action to avoid hitting a Chinese fighter jet that pulled in front of it over the East China Sea.

In May, an American warship sailed near a Chinese-held artificial island in the South China Sea, a mission intended to show international vessels’ freedom to navigate in an area China claims as exclusively its own. At the time, Beijing called those maneuvers a ”serious political and military provocation.”

On Thursday, Britain’s foreign secretary, Boris Johnson, committed his country’s newest and largest aircraft carriers to steam through the South China Sea.

“One of the first things we will do with the two new colossal aircraft carriers that we have just built is send them on a freedom of navigation operation to this area,” Mr. Johnson said during a visit to Sydney, Australia.

At 65,000 tons, Britain’s newest carrier, the Queen Elizabeth, is the largest ship ever built for the Royal Navy.