This is an appeal from a District Court judgment sustaining a demurrer in an action on a contract and *597a surety bond on the ground that the plaintiff did not allege facts sufficient to constitute a cause of action against one of the defendants, the surety. Plaintiff has appealed, contending that the District Court erred in sustaining the demurrer and in refusing to allow plaintiff leave to amend its petition. We reverse and remand for further proceedings.
Cagle, Inc., the plaintiff and appellant herein, filed a petition in the District Court for Douglas County on February 4, 1976, alleging that it, as a general contractor, entered into a subcontract with Jerry L. Sammons on August 21, 1975, under the terms of which Sammons was to complete drywall construction on a housing project. The petition alleged that Sammons furnished a performance bond, guaranteeing payment for labor and materials utilized by him in fulfilling the subcontract, and that the bond obligated Sammons and United States Fidelity & Guaranty Company (USF&G), the defendants and appellees herein, to make payments to claimants, as defined in the bond, for labor and materials used in performance of the subcontract. The subcontract and bond were attached to and made a part of the petition.
The petition further alleged that Sammons failed and refused to perform a substantial part of the work required by the subcontract; failed to pay costs and expenses incurred in performance of the subcontract for labor and materials; and failed to pay costs and expenses for labor and materials needed to complete his obligations following his withdrawal from the project. Cagle alleged that USF&G failed and refused to reimburse plaintiff as a claimant, as defined in the bond, for “costs and expenses for labor and material which Plaintiff has paid, or become obligated to pay” as a result of the breach of the subcontract and bond by Sammons. Cagle prayed for a judgment of $44,337.16, jointly and severally, against Sammons and USF&G.
*598On March 5, 1976, USF&G demurred to the petition on the ground that it failed to state facts constituting a cause of action against USF&G. Hearing was had on the demurrer of USF&G, and on June 29, 1976, the trial court sustained the demurrer. In its order, the trial court stated: “The court finds as a matter of law that plaintiff does not qualify as a ‘claimant’ under the bond as set forth in the petition, and, accordingly, that the demurrer should be sustained. The court further finds by reason thereof that no amendment of the petition in an action on the bond against said defendant would correct the deficiency or state a cause of action, and that the action should therefore be dismissed as against United States Fidelity and Guaranty Company.” Cagle’s motion for rehearing and new trial was overruled, and it has now appealed to this court, contending that the District Court erred in sustaining the demurrer, in dismissing the action against USF&G, and in refusing to allow Cagle leave to amend its petition.
A general demurrer such as the one in this case “tests the substantive legal rights of the parties upon admitted facts including proper and reasonable inferences of law and fact which may be drawn from the facts which are pleaded. A petition is sufficient if from the statement of facts set forth therein the law entitles the plaintiff to recover.” Lee v. Brodbeck, 196 Neb. 393, 243 N. W. 2d 331 (1976). A demurrer reaches an instrument filed with the petition and made a part thereof. Prucha v. Department of Motor Vehicles, 172 Neb. 415, 110 N. W. 2d 75 (1961). Therefore, it was appropriate for the trial court to refer to the surety bond, which plaintiff attached to and made a part of its petition, in determining whether the petition stated a cause of action against USF&G.
The bond was a “Subcontract Labor and Material Bond,” and was executed by Sammons as principal and USF&G as surety. The obligee under the bond *599was Red Oak Housing Agency, which was the owner of the construction project involved in this case. USF&G agreed under the bond to bind itself to the obligee “for the use and benefit of claimants as hereinbelow defined, in the amount” of $24,000. The bond defined “claimant” as follows: “A claimant is defined as one having a direct contract with the Principal for labor, material, or both, used or reasonably required for use in the performance of the contract, * * The bond provided that the principal and surety agreed that every claimant “may sue on this bond for the use of such claimant.” The trial court found as a matter of law that the plaintiff, under the facts alleged in its petition, did not qualify as a claimant under the bond.
Cagle contends that it does qualify as a claimant under the bond because it had a direct contract with Sammons for labor or material, or both, as required in the definition of “claimant” set forth in the bond. Cagle relies on a provision in the subcontract, which was made a part of the bond by reference, providing that in the event of Sammons’ default on the subcontract, Cagle was entitled to take over the subcontract and complete the same, and to charge the cost thereof to Sammons. We do not find this argument persuasive.
Generally speaking, contractors’ bonds are of two types: Performance bonds, and labor and material payment bonds. “A performance bond gurantees that the contractor will perform the contract, and usually provides that if the contractor defaults and fails to complete the contract, the surety can itself complete the contract or pay damages up to the limit of the bond. A labor and material payment bond guarantees the owner that all bills for labor and materials contracted for and used by the contractor will be paid by the surety if the contractor defaults.” 17 Am. Jur. 2d, Contractors’ Bonds, § 1, p. 192. A relevant case recognizing this distinction *600is Standard Accident Ins. Co. of Detroit v. Rose, 314 Ky. 233, 234 S. W. 2d 728 (1950). In that case, the court had to construe a bond which had provisions almost exactly like those in the bond in this case. The court found that the provisions of the bond meant that the surety would guarantee that all bills for labor or materials contributed for and used by the contractor would be paid by the surety if the contractor defaulted. The court rejected the argument that the bond covered all labor and materials used in completion of the building contract after the contractor defaulted, finding that the bond covered only labor and materials provided to the contractor while he was on the job.
The bond in this case is a labor and material bond, and not a general performance bond. The bond is in no way ambiguous, and USF&G bound itself only to pay persons having a direct contract with Sammons for labor or materials used or reasonably required for use in the performance of the subcontract. The general rule is that the “surety is bound in the manner and to the extent provided in the obligation.’’ School District No. 65R of Lincoln County v. Universal Surety Co., 178 Neb. 746, 135 N. W. 2d 232 (1965). See, also, W. T. Rawleigh Co. v. Smith, 142 Neb. 527, 7 N. W. 2d 80 (1942).
In this case Cagle did not state facts in its petition sufficient to state a cause of action against USF&G as a claimant under the bond. The subcontract provision permitting Cagle to take over the subcontract on Sammons’ default and to charge the cost to Sammons does not make Cagle a claimant as defined in the bond, for in such a situation Cagle would have no direct contract with Sammons to provide labor or materials to Sammons. Therefore it was proper for the District Court to sustain the demurrer on the ground that the facts, as alleged in the petition, did not state a cause of action against USF&G. Cagle did not allege that it had a direct contract with Sam*601mons to provide labor or materials to Sammons, and the fact that Cagle could take over the subcontract on Sammons’ default does not bring Cagle within the definition of a claimant as set forth in the bond.
The sustaining of a demurrer, however, does not bring the action to an end. Kohler v. Ford Motor Co., 187 Neb. 428, 191 N. W. 2d 601 (1971). Section 25-854, R. R. S. 1943, provides that if “the demurrer be sustained, the adverse party may amend, if the defect can be remedied by way of amendment, with or without costs, as the court in its discretion shall direct.” The right to amend is not absolute, and an application to amend is addressed to the sound discretion of the trial court. Before error can be predicated upon the refusal of the trial court to permit an amendment, the record must show that the ruling of the court was an abuse of discretion. Weiner v. Morgan, 175 Neb. 656, 122 N. W. 2d 871 (1963). In the present case, when the trial court sustained the demurrer, it found no amendment of the petition would correct its deficiency or state a cause of action, and dismissed the petition.
Cagle contends that it should have been permitted to amend its petition because it can allege facts which will permit recovery on the bond under the doctrine of subrogation. USF&G contends that subrogation is not available to Cagle. The parties agree that any person providing labor or materials to Sammons under a direct contract could sue on the bond. At issue is whether Cagle can be subrogated to the claims of persons who provided Sammons labor or materials, and whom Cagle paid after Sammons withdrew from the job. We note that Cagle did allege in its petition that USF&G had refused to reimburse it for “costs and expenses for labor and material which Plaintiff has paid, or become obligated to pay.” Although this allegation is not specific, it could very well include payment to persons *602who provided Sammons materials or labor before Sammons withdrew from the job.
“The doctrine of subrogation includes every instance in which one person pays a debt for which another is primarily liable, and which in equity and good conscience should have been discharged by the latter, so long as the payment was made under compulsion or for the protection of some interest of the one making the payment and in discharge of an existing liability.” Sheridan v. Dudden Implement, Inc., 174 Neb. 578, 119 N. W. 2d 64 (1962). The doctrine applies where a party is compelled to pay the debt of a third person to protect his own rights or interest, or to save his own property. Luikart v. Buck, 131 Neb. 866, 270 N. W. 495 (1936); 73 Am. Jur. 2d, Subrogation, § 11, p. 605. The doctrine of subrogation is not administered by courts of equity as a legal right, but the principle is applied to subserve the ends of justice and to do equity in the particular case under consideration. It does not rest on contract and no general rule can be laid down which will afford a test for its application in all cases. The facts and circumstances of each case determine whether the doctrine is applicable. Rapp v. Rapp, 173 Neb. 136, 112 N. W. 2d 777 (1962); Jones v. Rhodes, 162 Neb. 169, 75 N. W. 2d 616 (1956); Equitable Life Assurance Society of the United States v. Person, 135 Neb. 800, 284 N. W. 260 (1939).
It is well settled, however, that subrogation is never awarded in equity to one who is merely a volunteer in paying the debt of one person to another. Sharp v. Citizens Bank of Stanton, 70 Neb. 758, 98 N. W. 50 (1904); 73 Am. Jur. 2d, Subrogation, § 23, p. 612. A payment of a liability of another by one who is under no legal or moral obligation to pay the same does not entitle the volunteer to subrogation in the absence of an agreement to that effect. Freeport Motor Cas. Co. v. McKenzie Pontiac, Inc., 171 Neb. 681, 107 N. W. 2d 542 (1961); Scandinavian Mut. Ins. *603Co. v. Chicago B. & Q. R. R. Co., 104 Neb. 258, 177 N. W. 178 (1920). Ordinarily one seeking subrogation must plead it and set forth the facts out of which the right of subrogation arises. 73 Am. Jur. 2d, Subrogation, § 140, p. 689.
USF&G contends that the doctrine of subrogation is not available to Cagle in this case because Cagle was a volunteer if it paid persons who supplied labor or materials to Sammons before Sammons withdrew from the job. The record, at this point, does not support such a conclusion. The issue raised is whether Cagle, if it did make payments to persons who supplied labor or materials to Sammons, made such payments for the protection of its own rights or interest. Luikart v. Buck, supra. As a general contractor in a position where its subcontractor had withdrawn from the job, Cagle may well have had to make such payments to protect its own interests in the project, to enable itself to complete its contract with the owner, or to prevent liens from being filed on the property. This court has previously held that persons may be subrogated to the rights of material-men in situations analogous to the one allegedly presented in this case. See Karel v. Basta, 103 Neb. 191, 170 N. W. 891 (1919).
We conclude that it may well be possible for Cagle to state a cause of action on the bond under the doctriné of subrogation if it limits its claim to the value of payments it made to persons who supplied labor or materials to Sammons under a direct contract before Sammons withdrew from the job. Although Cagle’s petition as filed did not state such a cause of action due to Cagle’s misinterpretation of the bond as a performance bond rather than a labor and materials bond, it should be given an opportunity, to amend its petition and plead subrogation and the facts out of which the alleged right of subrogation arises. We note that USF&G complains that Cagle tendered no proposed amendment in connection with *604its request to amend; however, in light of the trial court’s finding that no amendment could state a cause of action, we agree with Cagle that the tendering of an amendment would have been a futile and useless gesture. The trial court erred in finding that no amendment of the petition would state a cause of action. It “generally constitutes an abuse of discretion to sustain a demurrer without leave to amend where there is a reasonable possibility that the defect can be cured by amendment, particularly in the case of an original complaint.” 61 Am. Jur. 2d, Pleading, § 285, p. 695. We feel the ends of justice will be served in this case by permitting plaintiff to amend its petition. Therefore we reverse the judgment and remand the cause to the District Court for further proceedings not inconsistent with this opinion.
Reversed and remanded.