Let's say someone gives you a class, Super
, with the following constructors:
public class Super
{
public Super();
public Super(int arg);
public Super(String arg);
public Super(int[] arg);
}
And let's say you want to create a subclass Derived
. How do you conditionally call a constructor in Super
?
In other words, what is the "proper" way to make something like this work?
public class Derived extends Super
{
public Derived(int arg)
{
if (some_condition_1)
super();
else if (some_condition_2)
super("Hi!");
else if (some_condition_3)
super(new int[] { 5 });
else
super(arg);
}
}