I'm doing this exercise:
Consider that you are developing a Java program where you work with the Professor superclass and the ProfessorEmerit subclass. Create code for to these classes that meet the requirements we indicate.
As attributes of the superclass we will have name (String), age (int) and anysConsolidats (int) declared as protected.
The subclass will work with the declared aysEmerit additional field as private.
A method of the subclass will be double getSalariBase () that you will get base salary as (925 + anysConsolidats * 33.25 + 47.80 * anysEmerit).
Try to access the aynsConsolidats field directly from the subclass (as if it were one more field of the subclass) to implement this method. It is possible without using a super invocation or a get method? What happens if the attribute to the superclass you declare private?
I have done this part of the code:
Professor:
//Atributos
protected String nom;
protected int edat, anys_consolidats;
ProfessorEmerit:
package Practica3_EX2;
public class ProfessorEmerit extends Professor{
//Atributos
private int anyEmerit;
//Metodos especiales
public double obtenirSalariBase(double salariBase) {
return salariBase=(925+anys_consolidats*33.25+47.80*anyEmerit);
}
}
But I have many doubts, for example, the method to obtain SalariBase () that must be done in the subclass, I have to create a variable called base salary? Something like this:
//Metodos especiales
public double obtenirSalariBase(double salariBase) {
return salariBase=(925+anys_consolidats*33.25+47.80*anyEmerit);
}