SAN JOSE, Calif. (AP) _ An attorney accused of having an affair with a client's wife has testified it would have been physically impossible because he has been impotent since 1978.

The testimony by William Melcher on Wednesday in Santa Clara County Superior Court came on the third day of Robert Singer's hearing for a new trial, which continued Thursday.

The disclosure elicited gasps from courtroom spectators and apparent astonishment from one of Singer's attorneys, Patrick Hallinan, who buried his head in his hands. Singer, convicted of murder in 1982, contends the affair made it impossible for Melcher to defend him competently.

Judi Singer says she slept with Melcher during both of her husband's murder trials. The first trial ended in a hung jury in 1981. A year later, the defendant was convicted of arranging the murder of Ms. Singer's first husband, businessman Howard Witkin, and sentenced to life in prison without parole.

Melcher testified the affair was a story concocted even before the trials to try to clear Singer if he was convicted. He said he was ''absolutely enraged'' by claims of the affair, and said love letters to him from Ms. Singer were either planted in his files or intercepted by his secretary.

Singer earlier testified he knew nothing of the affair until he was provided with copies of the letters by the secretary, Linda Bennett.

Melcher testified he has been ''totally impotent'' since a vasectomy eight years ago and has had no sexual activity with anyone, including his wife.

He said Singer told him on the day he was sentenced that he had a pact with his wife.

''He said, 'Judi's working on something. We have a fail-safe position. She's been working on it all the time,''' Melcher said.

He said Singer told him the couple's eventual divorce was ''simply going to make it look better when she's helping me behind the scenes.''

Melcher also claimed Singer told him that if his wife didn't carry out her part of the pact, he would implicate her in Witkin's murder.

Judge Robert M. Foley indicated in court that he intends to rule against Robert Singer's petition unless his lawyers can prove two elements: that the affair occurred and that it caused actual harm to Singer's defense.

Singer's attorneys have contended they don't have to prove Melcher made bad decisions during the trial if they can simply prove the affair occurred. They say the affair's existence would poison the attorney-client relationship so thoroughly that all of the attorney's later decisions would be tainted.

Deputy district attorneys Lane Liroff and Jack Marshall, who are opposing the new trial plea, have argued harm to Singer's defense must be shown for another trial to be granted.