Define an abstract attribute in a non-abstract class

1

I want to be able to instantiate an employee class (so this can not be abstract) and have an abstract salary attribute that will be static for each employee type.

I can do (in the official class):

private abstract int salario;

and its subclasses:

private static int salario = x,

where x is the value that I want to be for each subclass?

    
asked by anonymous 19.11.2017 / 14:52

1 answer

0

If you intend to prevent setSalario () you can put the setSalario method as private and call it with the setCargo () method

Example

public class Funcionario{
    private float salario;
    private String cargo;

    public void setCargo(String cargo){
        this.cargo = cargo;
        setSalario();
    }

    private void setSalario(){
        if(this.cargo.equals("nomeDoCargo"){
            this.salario = <valor>;
        }
        else if(...){
           ...
        }
        ...
    }
}

So you protect your salary and only allow it to change if you change the job.

    
19.11.2017 / 16:52