This is not 100% related your problem. But this is also related to java constructors. Let's say your Person class has no default constructor and the constructor parameters are not primitive data type. They are objects.
But If you want to create a subclass with a default constructor, here is the solution.
And keep it mind you are not allowed to change the super class.
I created a another class called contact.
class Contact{
private String name;
private int number;
public Contact(String name, int number) {
this.name = name;
this.number = number;
}
}
Then here is the code.
//Super Class - "Can't change the code"
class Person {
Person(Contact contact) { }
}
//Sub Class
class Employee extends Person {
private static Contact c;
static {
c = new Contact("Anna",10);
}
Employee() {
super(c);
}
}
You have to static variable of Contact class to keep a object instance for passing to super class constructor.