Virginia's two Democratic candidates for governor traded polite but sharp criticisms of each other tonight in their fourth face-to-face debate, a week before crucial delegate selection caucuses.

Lt. Gov. Richard J. Davis opened the 90-minute program at the Richmond Marriott Hotel, attacking his opponent, state Attorney General Gerald L. Baliles, for alleged inconsistencies on several issues.

"You can't have it both ways, Jerry," Davis said before a crowd of about 400.

Davis, former mayor of Portsmouth, Va., contends that Baliles, who was appearing before a mostly home-town audience, had exaggerated his support for environmental protections, the Equal Rights Amendment and other issues.

Baliles, appearing more relaxed and more confident than during some previous public appearances, largely ignored Davis' criticisms, and instead hammered away on what he calls the "electability issue" and a "willingness to work," both indirect criticisms of Davis's losing 1982 race for the U.S. Senate.

"I think I'm the only candidate that has the energy, the drive and the determination to . . . win in November," Baliles said.

Baliles and Davis differed on the state's current system of selecting judges. Virginia is one of the few states where the legislature, which in Virginia is controlled by Democrats, elects judges.

Davis said the system has worked well but Baliles said he believes the legislature should hold public hearings, which are not now required, before making judicial selections. "I believe the public has the right to be involved," Baliles said.

Baliles also indicated he would support giving localites the option of electing school board members, who are now either appointed by local governments or nominating commissions. Davis said he did not favor electing school board members.

Baliles, a former state legislator, said the state should be prepared for additional cuts in federal aid and said recent Supreme Court decisions could sharply increase state spending requirements. He said the state must be ready to reconsider its spending priorities and to promote economic expansion to help cover those costs.

Both candidates took strong stands in opposition to government controlled prayer in public schools.

"Anyone now . . . has a right to pray," Davis said. "I would not urge or support or . . . encourage" organized spoken prayer.

"I do not believe it is the role of government to write prayers or mandate prayers," Baliles said.

The Virginia Democratic Party will hold a series of mass meetings across the state on March 30 and April 1 to select about 3,500 delegates to the party's June 7 nominating convention in Richmond.

Party leaders say they expect the nomination fight to be close but that one of the two candidates is likely to emerge from the caucuses with a clear majority of delegates.

Both candidates, who will hold their last debate next Wednesday in Northern Virginia, pledged tonight to support the party's nominee.