This file contains hidden or 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 ExemploInstanceof { | |
| public static void main(String[] args) { | |
| Object obj = new String("Texto"); | |
| if (obj instanceof String) { | |
| System.out.println("obj é uma instância de String"); | |
| } | |
| } |
This file contains hidden or 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 Animal { | |
| private String nome; | |
| private int idade; | |
| } |
This file contains hidden or 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
| package classeAbstrata; | |
| public class TV extends Eletrodomestico { | |
| private int tamanho; | |
| private int canal; | |
| private int volume; | |
| /* implementação dos métodos abstratos */ | |
| public void desligar() { | |
| super.setLigado(false); |
This file contains hidden or 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
| package classeAbstrata; | |
| public abstract class Eletrodomestico { | |
| private boolean ligado; | |
| private int voltagem; | |
| // métodos abstratos // | |
| /* | |
| * não possuem corpo, da mesma forma que | |
| * as assinaturas de método de uma interface |
This file contains hidden or 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 interface ControleRemoto { | |
| /* | |
| * Perceba que apenas a assinatura dos métodos estão aqui. | |
| * E cada método termina com um ponto-e-vírgula (;) | |
| */ | |
| void mudarCanal(int canal); | |
| void aumentarVolume (int taxa); | |
| void diminuirVolume (int taxa); | |
| boolean ligar(); |
This file contains hidden or 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 Eletrodomestico { | |
| protected boolean ligado; | |
| protected int voltagem; | |
| protected int consumo; | |
| // getters e setters | |
| // ... | |
| } |
This file contains hidden or 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 TV { | |
| private int tamanho; | |
| private int canal; | |
| private int volume; | |
| private boolean ligada; | |
| // construtor vazio (sem parâmetros) | |
| public TV() { | |
| } |
This file contains hidden or 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 MinhaClasse { //classe public | |
| private int inteiro; //atributo inteiro private | |
| protected float decimal; //atributo float protected | |
| boolean ativado; //atributo booleano default/padrão | |
| } |
This file contains hidden or 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
| package classes; | |
| import javax.swing.JOptionPane; | |
| public class Mensagem { | |
| public static void main (String args[]){ | |
| JOptionPane.showMessageDialog(null, "Bem vindo ao mundo de Java!"); | |
| } | |
| } |
This file contains hidden or 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 Main{ | |
| public static void main (String args []){ | |
| TV minhaTV = new TV(); | |
| System.out.println(minhaTV.volume); | |
| minhaTV.aumentarVolume(); | |
| System.out.println(minhaTV.volume); | |
| } | |
| } |