How to implement an abstract method in a child class?

I abstracted a method from an also abstract class.

But I'm not knowing how to implement this method in the child class.

Here's my code, what do I get?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Banco_Exercicio1
{
    public class Cliente
    {


        public string Nome { get ; set ;}
        public string Rg { get ; set ;}
        public string Cpf {get ; set ;}

        public Cliente(string nome)
        {            
            this.Nome = nome;
        }
    }

    public abstract class Conta
    {
        public Cliente Titular { get; set; }
        public double Saldo { get; set; }
        public int Numero { get; set; }

        public Conta(Cliente nome)
        {
            this.Titular = nome;
        }

        public Conta() {}

        public abstract void Depositar(double Valor) ;


        public abstract void Saca(double Valor);   

    }

    public class ContaPoupanca : Conta // Essa linha apresenta erro: does not implement inherited abstract member
    {
        public ContaPoupanca(Cliente nome) : base(nome) { }

        public ContaPoupanca() {}

        public override void Saca(double Valor)
        {
            base.Saca(Valor + 0.10);     //Error: Cannot Call an abstract member
        }      
    }

    public class ContaCorrente : Conta
    {
        public ContaCorrente(Cliente nome) : base(nome) { }

        public ContaCorrente() {}

        public override void Saca(double Valor)
        {
            base.Saca(Valor + 0.05);    //Error: Cannot Call an abstract member
        }

        public override void Depositar(double Valor)
        {
            base.Depositar(Valor - 0.10);   //Error: Cannot Call an abstract member
        }
    }

    public class TotalizadordeContas 
    {
        public double ValorTotal {get ; private set ;}

        public double Soma (Conta conta)
        {
            ValorTotal += conta.Saldo;
            return ValorTotal; 
        }
    }

}

How to resolve and fix these errors?

Http://social.technet.microsoft.com/Forums/pt-BR/054bda3b-40a6-4723-82ba-7c119ffdccd3/como-implementar-um-mtodo-abstrato-em-uma-classe-filha?forum=cermicrosoftpt#054bda3b-40a6-4723-82ba-7c119ffdccd3

Author: Leonel Sanches da Silva, 2014-04-09

2 answers

The base class method cannot be called, as it has no implementation in the base class.

The call to the base class method should be made when the method is virtual in the base class, and not when the method is abstract.

Parsing your code: from what I understood from your code, the base class should have some responsibility, so the method should be implemented in the base class as well, as a virtual method rather than abstract:

Suppose the base class has the responsibility to write to the database. In this case you could do like this:

public abstract class Conta
{

    public Cliente Titular { get; set; }
    public double Saldo { get; set; }
    public int Numero { get; set; }

    public Conta(Cliente nome)
    {
        this.Titular = nome;
    }

    public Conta() {}
    public virtual void Depositar(double Valor)
    {
        // exemplo: gravar o valor depositado no banco de dados
        // usando o seu ORM
    }


    public virtual void Saca(double Valor)
    {
        // exemplo: gravar o valor sacado no banco de dados
        // usando o seu ORM
    }
}
 4
Author: Miguel Angelo, 2014-04-09 20:57:30

Does not implement inherited abstract member

Implement Depositar in ContaPoupanca:

public override void Depositar(double Valor) { ... }

Cannot call an abstract member

The message already says it all. Since in the base class the method is abstract, it does not have to be called. Therefore, you cannot use base.

As @MiguelAngelo said, if the goal is for the base method to be called, use virtual.

 1
Author: Leonel Sanches da Silva, 2014-04-09 20:56:47