Adriano Souza Posted November 30, 2022 Share Posted November 30, 2022 aparece isso: No enclosing instance of type Temperatura is accessible. Must qualify the allocation with an enclosing instance of type Temperatura (e.g. x.new A() where x is an instance of Temperatura) segue codigo: public class Temperatura { private int calcTemperatura; public int gettemperatura() { return calcTemperatura ; } public void settemperatura(int calcTemperatura) { this.calcTemperatura = calcTemperatura; } public int calculaTemperatura(){ return this.calcTemperatura * 1; } //subclasse Umidade public class Umidade extends Temperatura{ private int umidade; public int getUmidade() { return umidade; } public void setUmidade(int umidade) { this.umidade = umidade; } //calculando temperatura para sair a umidade public double calculaUmidade(){ return this.gettemperatura() * 0.6 + 100; } // classe testadora public class TestaSensor { public static void main(String[] args) { //temperatura Temperatura temperatura = new Temperatura(); temperatura.settemperatura(20); //Umidade Umidade umidade = new Umidade(); umidade.setUmidade(15); System.out.println("Temperatura é...: "+temperatura.gettemperatura()); System.out.println("Umidade.: "+umidade.getUmidade()); } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now