无法调用抽象成员

编程入门 行业动态 更新时间:2024-10-27 11:18:47
本文介绍了无法调用抽象成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我做我的,在我处理的抽象类,C#功课。

I am doing my homework in C# in which I dealing with abstract class.

public abstract class Account { public abstract bool Credit(double amount); public abstract bool Debit(double amount); } public class SavingAccount : Account { public override bool Credit(double amount) { bool temp = true; temp = base.Credit(amount + calculateInterest()); return temp; } public override bool Debit(double amount) { bool flag = true; double temp = getBalance(); temp = temp - amount; if (temp < 10000) { flag = false; } else { return (base.Debit(amount)); } return flag; } }

在我所说的base.Debit()或基地.Credit(),那么它给了我无法调用抽象成员错误。 请帮帮我。

When I call the base.Debit() or base.Credit() then it gives me error of cannot call an abstract member. Please help me.

推荐答案

您不能调用抽象方法,这个想法是,一个方法声明为abstract只需要派生类来定义它。使用 base.Debit 在影响试图调用一个抽象方法,它无法做到的。更仔细地阅读你的代码,我觉得这是你想要什么借记()

You cannot call abstract methods, the idea is that a method declared abstract simply requires derived classes to define it. Using base.Debit is in affect trying to call an abstract method, which cannot be done. Reading your code more closely, I think this is what you wanted for Debit()

public abstract class Account { protected double _balance; public abstract bool Credit(double amount); public abstract bool Debit(double amount); } public class SavingAccount : Account { public double MinimumBalance { get; set; } public override bool Debit(double amount) { if (amount < 0) return Credit(-amount); double temp = _balance; temp = temp - amount; if (temp < MinimumBalance) { return false; } else { _balance = temp; return true; } } public override bool Credit(double amount) { if (amount < 0) return Debit(-amount); _balance += amount; return true; } }

更多推荐

无法调用抽象成员

本文发布于:2023-11-16 10:17:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603388.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:抽象   成员

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!