Created
September 18, 2020 12:40
-
-
Save sergiosvieira/513d53d83421a680632a75ba1c0800b4 to your computer and use it in GitHub Desktop.
Semana 02 - Herança
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exemplo de herança entre as classes Conta, Conta Corrente e Conta Poupança. | |
Linguagem C++ | |
============= | |
class Conta { | |
protected: | |
int numero; | |
string titular; | |
double saldo_atual; | |
public: | |
double rendimento() { | |
return 0.0; | |
} | |
}; | |
class Corrente: public Conta { | |
} | |
class Poupanca: public Conta { | |
public: | |
double rendimento() override { | |
return this->saldo_atual * 1.01; | |
} | |
} | |
Linguagem Java | |
================ | |
public class Conta { | |
protected int numero; | |
protected string titular; | |
protected double saldo_atual; | |
public: | |
double rendimento() { | |
return 0.0; | |
} | |
}; | |
public class Corrente extends Conta { | |
} | |
public class Poupanca extends Conta { | |
public: | |
double rendimento() { | |
return this->saldo_atual * 1.01; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment