I have Java code that looks something like this:
public class Animal { Animal(String name) { // some code } } And a subclass like this:
public class Dog extends Animal { Dog(String name) { // SAME code as Animal constructor } } The only difference between Dog and the Animal is that Dog has some methods that override the superclass. Their constructors have exactly the same code. How can I avoid this duplicated code? I know that an object can't inherit constructors.