Created
July 5, 2020 23:12
-
-
Save adilsoncarvalho/8ff603eb18a54996cdf888fc81d91d3c to your computer and use it in GitHub Desktop.
Exemplo de herança para o Ney
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
public class Dependente { | |
public int getIdade() { return 123356777889; } | |
} | |
public abstract class Funcionario { | |
public boolean addDependente(Dependente dependente) { | |
if (dependentes.count() == 5) return false; | |
if (!dependenteValido(dependente)) return false; | |
dependentes.add(dependente); | |
} | |
public dependenteValido(Dependente dependente) { | |
return dependente.getIdade() < getIdadeMaximaDependente(); | |
} | |
public abstract int getIdadeMaximaDependente(); | |
} | |
public class FuncionarioTemporario extends Funcionario { | |
public int getIdadeMaximaDependente() { | |
return 17; | |
} | |
} | |
public class FuncionarioConcursado extends Funcionario { | |
public int getIdadeMaximaDependente() { | |
return 21; | |
} | |
} | |
Funcionario temporario = new FuncionarioTemporario(); | |
Funcionario concursado = new FuncionarioConcursado(); | |
Dependente dep13 = new Dependente(); // idade 13 anos | |
Dependente dep21 = new Dependente(); // idade 21 anos | |
temporario.addDependente(dep13); // true | |
temporario.addDependente(dep21); // false | |
concursado.addDependente(dep13); // true | |
concursado.addDependente(dep21); // true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment