
42 Cal.2d 675 (1954)
H. J. WILSON, Appellant,
v.
WILLIAM G. SHARP et al., Defendants; HAROLD W. KENNEDY, Respondent.
L. A. No. 22980. 
Supreme Court of California. In Bank.  
Apr. 13, 1954.
 John J. Guerin for Appellant.
 Harold W. Kennedy, County Counsel (Los Angeles), John B. Anson and Arvo Van Alstyne, Deputy County Counsel, for Respondent.
 GIBSON, C.J.
 Plaintiff, a taxpayer, seeks by this action on behalf of Los Angeles County to recover from defendant Sharp and several officers of the county the salary paid by the county to Sharp, to enjoin further payment of salary to him, and to obtain a judgment declaring the rights and duties of the parties. Defendant Harold W. Kennedy, County Counsel, was not named as a defendant in the original or the first amended complaint but was made a defendant for the first time in the second amended complaint. The sole basis for recovery alleged as to him appears in the second count of the complaint, which purports to state a cause of action only against him. The trial court granted a motion to strike the second count, and plaintiff has appealed from the order granting the motion.
 The original complaint and the two amended complaints allege as follows: The Los Angeles County Civil Service Commission called a promotional examination to fill a vacancy in the classified services and knowingly fixed the requirements so that only Sharp could qualify. The commission made an eligible list showing that Sharp was the only applicant and determined his rating by investigation rather than by competitive examination. After certification by the commission, the county clerk appointed Sharp to the position, and he was paid for his services out of public funds. It was further averred that the eligible list and Sharp's appointment were void and that the payment of public money to him was unauthorized. *677
 In the second cause of action of the second amended complaint, which is the one involved here, it is alleged that Kennedy, as County Counsel, was given written notice of the assertedly illegal payments and that he failed, after demand, to institute an action against Sharp. Plaintiff seeks to recover the portion of the salary paid to Sharp which was barred by the statute of limitations at the time this action was commenced. He claims that the barred payments could have been recovered if timely suit had been brought by the county counsel.
 [1] The order granting the motion to strike operated to remove from the case the only cause of action alleged against the county counsel and to leave no issues to be determined between him and plaintiff, and it was appealable as a "final judgment" within the meaning of section 963 of the Code of Civil Procedure.  [fn. *] (Young v. Superior Court, 16 Cal.2d 211, 214-215 [105 P.2d 363]; Howe v. Key System Transit Co., 198 Cal. 525 [246 P. 39]; People v. Buellton Dev. Co., 58 Cal.App.2d 178, 181 [136 P.2d 793]; County of Humboldt v. Kay, 57 Cal.App.2d 115, 119 [134 P.2d 501]; see Herrscher v. Herrscher, 41 Cal.2d 300, 303-304 [259 P.2d 991].)
 The motion to strike was made on the ground that specified allegations were irrelevant, and it was argued that the second cause of action attempted to set up, by way of amendment, a wholly different cause of action based upon a wholly different legal liability. It is unnecessary to consider whether the trial court should have granted the motion on the grounds stated because, as we shall see, the stricken matter fails to state a cause of action, and plaintiff was not prejudiced by the ruling. (See Wilson v. Shea, 194 Cal. 653, 659 [229 P. 945]; Barr Lumber Co. v. Shaffer, 108 Cal.App.2d 14, 23 [238 P.2d 99]; Neal v. Bank of America, 93 Cal.App.2d 678, 683 [209 P.2d 825].) [2] The objection that a complaint does not state a cause of action is not waived by a failure to demur and may be raised at any time. (Code Civ. Proc.,  434; Horacek v. Smith, 33 Cal.2d 186, 191 [199 P.2d 929]; Ryan v. Holliday, 110 Cal. 335, 337 [42 P. 891].)
 The stricken cause of action seeks relief on the theory that section 26525 of the Government Code imposed on the *678 county counsel a mandatory duty to institute proceedings to recover assertedly unauthorized payments to Sharp. Section 26525 provides in part: "If the board of supervisors without authority of law orders any amount paid ... and the money is actually paid, or if any county officer draws any warrant ... without authorization by the board or law and the warrant is paid, the district attorney shall institute suit in the name of the county to recover the money paid, and 20 per cent damages for the use thereof." It is conceded that the County Counsel of Los Angeles County has the functions and duties of a district attorney under this statute, and we will discuss the problem as if the statute expressly mentioned the county counsel.
 [3] Section 26525 creates a cause of action against the recipients of illegal payments. (Miller v. McKinnon, 20 Cal.2d 83, 95-96 [124 P.2d 34, 140 A.L.R. 570]; County of Santa Barbara v. Janssens, 177 Cal. 114, 118 [169 P. 1025, L.R.A. 1918C 558]; see Galli v. Brown, 110 Cal.App.2d 764, 778-779 [243 P.2d 920].) It does not, however, purport to create a cause of action against a district attorney or county counsel, and we must consider whether, under general principles of law, an action will lie for failure to institute suit against the recipient of illegal payments. [4] The references in the statute to payments ordered and made "without authority of law" or "without authorization by the board or law" show that the decision as to whether the circumstances of a particular case warrant the institution of proceedings is a matter involving the determination of questions of law and fact. Such a determination necessarily requires the exercise of discretion, and it would seem obvious that the legal officer of the county is the proper person to exercise this discretion. (See Boyne v. Ryan, 100 Cal. 265, 267 [34 P. 707]. Compare Board of Supervisors v. Simpson, 36 Cal.2d 671 [227 P.2d 14] [mandate granted where statute imposed nondiscretionary duty upon district attorney to bring abatement action when so directed by board of supervisors].) The Boyne case was decided when the statute on which section 26525 is based provided, in somewhat stronger language, that it was the "duty" of the district attorney to institute suit to recover illegal payments. It was nevertheless held that he was vested with discretion and could not be compelled by mandamus to bring suit. The same discretion is vested under the present statute.
 [5] In exercising his discretion, the county counsel must *679 determine not only whether there has been a violation of law but also whether action is justified under all the facts, and the public welfare requires that the decision should be made free from fear of civil liability. A clear analogy is to be found in the cases holding that officials who are directly connected with the judicial processes are immune from civil liability while acting within the scope of their authority. (White v. Towers, 37 Cal.2d 727, 729 et seq. [235 P.2d 209, 28 A.L.R.2d 636] [malicious prosecution, fish and game investigator]; Coverstone v. Davies, 38 Cal.2d 315, 322 [239 P.2d 876] [malicious prosecution, sheriff]; Turpen v. Booth, 56 Cal. 65, 68 [38 Am.Rep. 48] [grand juror]; Downer v. Lent, 6 Cal. 94 [95 Am.Dec. 489] [pilot commissioners, revocation of pilot's license]; Norton v. Hoffmann, 34 Cal.App.2d 189, 198-199 [93 P.2d 250] [malicious prosecution, city attorney]; White v. Brinkman, 23 Cal.App.2d 307, 311 [73 P.2d 254] [malicious prosecution, district attorney]; Pearson v. Reed, 6 Cal.App.2d 277, 280 et seq. [44 P.2d 592] [prosecuting attorney].) [6] While the cases cited above concerned the question of liability for affirmative action, it would seem clear that the same rule of immunity should apply where, as here, the county counsel refrains from acting in a matter coming within the scope of his authority and where his decision to act or refrain from acting necessarily involves the exercise of discretion. [7] It follows that the second count of the second amended complaint fails to state a cause of action, hence plaintiff was not prejudiced by the order granting the motion to strike.
 The order is affirmed.
 Shenk, J., Edmonds, J., Traynor, J., Schauer, J., and Spence, J., concurred.
 CARTER, J.
 I dissent.
 The majority opinion holds that a county counsel (the same rule would apply to the district attorney if there were no county counsel) is not liable to the county for failure to take action for the recovery of county funds allegedly illegally paid to a third person, a county employee in this case. I assume, for the purposes of this dissent, as does the majority opinion, that the funds were illegally expended. The majority bases its conclusion on two grounds: (1) That it rests wholly within the discretion of the county counsel as to whether he will prosecute an action for the recovery of such funds, *680 and hence, he cannot be liable under any circumstances; (2) "public welfare" requires that he be not liable by analogy to the cases (White v. Towers, 37 Cal.2d 727 [235 P.2d 209, 28 A.L.R.2d 636]; Coverstone v. Davies, 38 Cal.2d 315 [239 P.2d 876]; Turpen v. Booth, 56 Cal. 65 [38 Am.Rep. 48]; Downer v. Lent, 6 Cal. 94 [95 Am.Dec. 489]; Norton v. Hoffmann, 34 Cal.App.2d 189 [93 P.2d 250]; White v. Brinkman, 23 Cal.App.2d 307 [73 P.2d 254]) holding that public welfare requires freedom on the part of certain officers in the performance of their duties from possible liability to third persons who are injured by their action or nonaction; and that the public's interest in having them fearlessly perform their duties outweighs the injury to third persons.
 The first ground is contrary to the holding of this court in Board of Supervisors v. Simpson, 36 Cal.2d 671 [227 P.2d 14]. In that case the question was whether the district attorney could be compelled by mandamus to prosecute an action to abate a public nuisance. We held that while ordinarily a district attorney could not be compelled to prosecute a criminal case, because, whether or not he prosecuted it rested in his discretion, but that a mandatory duty was imposed upon him to abate a nuisance and he had no discretion in the matter. We said: "As pointed out above, the district attorney must or shall bring an action to abate a public nuisance when so directed by the board of supervisors. (Code Civ Proc.,  731, supra; Gov. Code,  26528.) 'Shall' is mandatory (Gov. Code,  14), and certainly 'must' is also. The writ of mandamus issues '... to compel the performance of an act which the law specially enjoins, as a duty resulting from an office ...' (Code Civ. Proc.,  1085.) The statutes (Code Civ. Proc.,  731; Gov. Code,  26528) specifically 'enjoin' upon the district attorney 'as a duty resulting from (his) office' the bringing of actions to abate public nuisances when directed by the board of supervisors." (Emphasis added.) Similarly, in the case at bar, section 26525 of the Government Code provides that if county money is illegally expended the district attorney "shall" (emphasis added) institute suit to recover it. The duty is mandatory. He has no discretion in the matter. Even if there is some discretion it would be only in respect to the facts of the case--whether they were such as to show an illegal expenditure. The plaintiff in this action alleged that he gave all the facts to the county counsel, and as far as appears, the county counsel arbitrarily refused to bring an action to recover the illegal *681 payments; his refusal was not an exercise by him of his discretion on the facts, but a failure to perform his official duty.
 Reliance is placed upon Boyne v. Ryan, 100 Cal. 265 [34 P. 707], as showing the county counsel had discretion in the matter. It is not in harmony with the Simpson case and moreover the court said that if the district attorney "wilfully" refused to prosecute the action he could be proceeded against for malfeasance or nonfeasance in office. If that is true, certainly he should be liable to the county for his conduct.
 I cannot agree with the second ground. I reiterate the position I took in my dissents in White v. Towers, supra, 37 Cal.2d 727, and Coverstone v. Davies, supra, 38 Cal.2d 315, that public office holding should not be a cloak immunizing the officer from liability for his wrongful acts. In addition to that, however, the rule of those cases cannot apply to the case at bar. In those cases, according to the majority, the public welfare was preserved by enabling the officers to perform more effectively their public functions, and to achieve that purpose they should be free from liability to third persons injured in the course of the performance of official duty; that the public welfare so preserved was of such superior importance that the rights of the injured persons must give way. In the case at bar, however, no such situation exists. Here it is obvious that the public interest would be preserved by recovering the county funds illegally spent, as opposed, at the most, to the public interest achieved in fearless failure of the county counsel to perform his official duty by refusing to take the necessary action to protect the public interest. In fact there is no public interest achieved in having official duty performed when such performance consists of a refusal or failure to bring an action to recover such funds. The only way to preserve the public interest here is by the prosecution of such an action. In short, it cannot logically be said that the public interest is preserved by the failure of public officials to perform their official duty. Therefore, the analogy between this case and the cited cases completely fails. Indeed, under the facts here alleged, the public interest requires that the county counsel be held liable for failure to perform his official duty in prosecuting an action for the recovery of the funds allegedly illegally expended.
 I would reverse the judgment. *682
 "1. From a final judgment entered in an action, or special proceeding, commenced in a superior court, or brought into a superior court from another court; ...."
NOTES
[fn. *]  *. Section 963 of the Code of Civil Procedure reads in part, "An appeal may be taken from a superior court in the following cases:
