Created
August 6, 2021 01:18
-
-
Save tassioauad/9358d260b65b662cee670ccf03c7c0cc to your computer and use it in GitHub Desktop.
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 Aluno { | |
private Integer id; | |
private String nome; | |
private Float altura; | |
private Integer periodo; | |
public Aluno(Integer id, String nome, Float altura, Integer periodo) { | |
this.id = id; | |
this.nome = nome; | |
this.altura = altura; | |
this.periodo = periodo; | |
} | |
public Integer getId() { | |
return id; | |
} | |
public void setId(Integer id) { | |
this.id = id; | |
} | |
public String getNome() { | |
return nome; | |
} | |
public void setNome(String nome) { | |
this.nome = nome; | |
} | |
public Float getAltura() { | |
return altura; | |
} | |
public void setAltura(Float altura) { | |
this.altura = altura; | |
} | |
public Integer getPeriodo() { | |
return periodo; | |
} | |
public void setPeriodo(Integer periodo) { | |
this.periodo = periodo; | |
} | |
public String falarTipo() { | |
return "Aluno"; | |
} | |
} |
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 App { | |
public static void main(String[] args) { | |
Aluno aluno = new Aluno(1, "Tássio Auad", 1.70f, 6); | |
Aluno monitor = new Monitor(1, "Joaquim José da Silva Xavier", 2.0f, 6, 4); | |
Monitor novoMonitor = (Monitor) monitor; | |
novoMonitor.avaliarAluno(); | |
((Monitor) monitor).avaliarAluno(); | |
// Nesse caso, a variavel monitor só enxerga o que existe na classe Aluno porque "Aluno monitor". | |
//Porém, ele É UM MONITOR. A visibilidade que ele possui é de Aluno, mas ele é uma instância de Monitor. | |
//Isso é possível porque o Monitor é um Aluno. | |
Aluno bruce = new RepresentanteTurma(2, "Bruce Wayne", 1.80f, 6); | |
bruce = new Monitor(2, "Bruce Wayne", 1.80f, 6, 3); | |
RepresentanteTurma kelvyn = new RepresentanteTurma(3, "Kelvyn Telles", 1.74f, 6); | |
//kelvyn = new Monitor(3, "Kelvyn Telles", 1.74f, 6, 4); | |
System.out.println(monitor.falarTipo()); | |
} | |
} |
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 Monitor extends Aluno { | |
private Integer periodoMonitoria; | |
public Monitor(Integer id, String nome, Float altura, Integer periodo, Integer periodoMonitoria) { | |
super(id, nome, altura, periodo); | |
this.periodoMonitoria = periodoMonitoria; | |
} | |
public Integer getPeriodoMonitoria() { | |
return periodoMonitoria; | |
} | |
public void setPeriodoMonitoria(Integer periodoMonitoria) { | |
this.periodoMonitoria = periodoMonitoria; | |
} | |
@Override | |
public String falarTipo() { | |
return "Monitor"; | |
} | |
public void avaliarAluno() { | |
//Vazio | |
} | |
} |
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 RepresentanteTurma extends Aluno{ | |
public RepresentanteTurma(Integer id, String nome, Float altura, Integer periodo) { | |
super(id, nome, altura, periodo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment