Rambling along back roads in quest of independent voters, Arizona Sen. John McCain said today that he can identify a gay person "by behavior and by attitudes"--an assertion that was disputed by the nation's leading homosexual political group.

The Republican presidential contender made the assertion during a stop here at Calef's Country Store, where he bought a block of extra-sharp cheddar. The topic had arisen as McCain chatted with reporters aboard his campaign bus, the Straight Talk Express, where he said he had served in the Navy with many gays, although they had not told him of their sexual orientation. In the store, he was asked how he knew.

"Well, I think we know by behavior and by attitudes," he told a spray of television cameras. "I think that it's clear to some of us when some people have that lifestyle. But I didn't pursue it, and I wouldn't pursue it, and I wouldn't pursue it today."

Asked again if he can really tell when someone is gay, McCain backtracked. "I said I had suspicions, and I think that--I was told that they were," he said. "But, look: That, to me, was something--and still is something--that is private. It's very different from a manifestation of that behavior in the line of duty."

Although McCain disagrees with most parts of their agenda, gay rights groups have considered McCain the least objectionable of the Republican presidential candidates. He is the only one who has met with leaders of the Log Cabin Republicans, a gay group with 11,000 members, while Texas Gov. George W. Bush has said he probably would not.

After McCain's meeting on Nov. 8, he said he was eager to work with the group to end discrimination. He is the only current presidential candidate to receive donations through the group, which has passed on $40,000 to his campaign, according to Log Cabin officials.

McCain has said he would retain the military's "don't ask, don't tell" policy, which was designed to allow gays to serve, but not openly. "I think the policy works," he said at a town meeting tonight in Stratham, N.H., "but I am opposed to discrimination of any kind in America."

David M. Smith, communications director of the Human Rights Campaign, a gay political group based in Washington, said of McCain's ability to sense gays, "He has one up on me, because I can't tell just by behavior and attitudes."

"He is clearly stereotyping based on mannerisms," Smith said. "This is a form of prejudice, and illustrates the struggle that gay people face."

But Kevin D. Ivers, public affairs director of the Log Cabin Republicans, took McCain's observation in stride. "If there's a gay person anywhere who says they can't walk into a room and tell who some of the gay people are, they're lying," Ivers said. He added that these comments show that McCain "has been thinking about his entire life and when gay people may have played a role in it. He has reached across and said he wants to understand gay people, even though he doesn't always agree with them."

The exchange showed the risk of the free-wheeling style that has drawn so much attention to McCain, who holds forth for hours every day in the big red captain's chair at the back of the Straight Talk Express. He seems to enjoy the give-and-take, although in remarks to the Rotary Club in Rochester, N.H., this afternoon, McCain said jokingly of the reporters, as he often does, "Most of 'em are either communists or Trotskyites."

CAPTION: Sen. John McCain looks over a selection of cheese he was about to purchase at Calef's Country Store in Barrington, N.H.