I'm currently trying to learn Java and I encountered a problem on which I'm a little stuck.
I have one superclass and two subclasses that extend it, in the superclass I created an Arraylist that I want to use in the constructor of the subclasses but I'm not quite sure about my solution.
I would be glad for any help and please let me know if you need any further information in order to understand my question.
So here is what I've tried:
public class Superclass{
private String something;
private ArrayList<String> list;
public Superclass(String something){
this.something = something;
list = new ArrayList<String>();
}
}
public class Subclass extends Superclass{
public String someelse;
public Subclass(String name, ArrayList<String> list, String
someelse){
super(name);
this.someelse = someelse;
list = new ArrayList<String>
}
}
It doesn't through out any errors but is it the right way to do it like that, or is there a way to have the ArrayList in the super brackets? I want to initilize it the superclass, add elements in the subclasses and use it in a different class.