Inheritance is said that a subclass inherits all methods from a superclass. But when 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 gives error because the subclass can not manipulate the methods of the superclass directly. So what would it be like?