Q:

Inheritance, protected or setters, getters

I have the basis class.Animal(abstract)
and some classes (dog,cat...) extend this class.
I have some values that must be in every object of animal.
some function in dog,cat... use this values and sometimes change them.
I want if I need to create in Animal getter & setter to this values or put this values protected. what is the good way to do this.
also some of this values must be initialize.there is a way to do this values absract?

A:

I would make the properties protected in Animal, so that they can be referenced directly in subclasses (Dog and Cat), but have public getters and setters for access anywhere else.
public abstract class Animal {
    protected String species;
    ...
    public String getSpecies(){
        return species;
    }
    public void setSpecies(String species){
        this.species = species;
    }
}

