I have the following code;
abstract class Animal{
public String name;
public int legCount;
//If has no leg count
public Animal(String name){
this.name = name;
this.legCount = 4; //Default leg count is 4
System.out.println("Created animal: " + name);
}
//If has a leg count
public Animal(String name, int legCount){
this.name = name;
this.legCount = legCount;
System.out.println("Created animal: " + name);
}}
I have repeated System.out.println("Created animal: " + name); twice. Is there a way to remove this repeated code, so it only runs once? having multiple constructors can make this a bit of a pain.