Is it possible to set abstract class variable with default value of class which extends abstract class? I mean if I have abstract class Atrakcja:
public abstract class Atrakcja implements ElementWycieczki{
private double time;
public Atrakcja(double time)
{
this.time = time;
}
}
I want to set time variable by default value from
public class DrewnianaCerkiew extends Atrakcja{
private double time = 0.5;
public DrewnianaCerkiew(){
...
}
}
I know that if i would like to put parameter to constructor it would be easy, just put parameter to DrewnianaCerkiew constructor, then super(param) and it would set time. But in some classes which extends Atrakcja (abstract class) want to set default time.
One of solution what I want is to do is just: super(0.5);, but is there another way to make default value for class? It would be better if I can set default value to variable of class e.g. double time = 0.5; then super(time) but it doesn't work.
timeare "connected" and then get confused when methods insideAtrakcjawork with a different value than methods insideDrewnianaCerkiew.private double time = 0.5;with{ time = 0.5; }and change the definition oftimein the base class to beprotectedinstead ofprivate. With this said, you should use the techniques provided in the answers to this question.super(0.5);, but is there another way to make default value for class?" what is the problem with that solution? It looks clear, especially in IDEs which can show names of variables for which we provide values, so you will see it as something likesuper(time: 0.5).