1
Inheritance is said to inherit all the methods of a super class. But in doing
class Soma{
private double total;
public void setSoma(double s1, double s2)
{
total = s1+s2;
}
public double getSoma()
{
return total;
}
}
import java.util.Scanner;
class Calculos extends Soma{
public static void main(String[] args)
{
double v1, v2;
Scanner insere = new Scanner(System.in);
System.out.print("Digite o primeiro valor: ");
v1 = insere.nextDouble();
System.out.print("Digite o segundo valor: ");
v2 = insere.nextDouble();
setSoma(v1, v2);
System.out.printf("O resultado da soma é %.2f", getSoma());
}
}
It is an error because the subclass cannot directly manipulate the superclass methods. So how would it be?
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero