Override constructor

Is it possible to override a constructor? I want to take my code:
public class BusinessException
{
public BusinessException(int age)
{
}
}
public class BusinessException
{
public BusinessException(int age)
{
}
}
and translate it to:
public class BusinessException
{
private int age;

public BusinessException(int age)
{
this.age = age;
}
}
public class BusinessException
{
private int age;

public BusinessException(int age)
{
this.age = age;
}
}
In the example, I add a private field age, but if it's not possible it's ok, I'll be happy with just overriding the constructor
Gael Fraiteur
Gael Fraiteur311d ago
You cannot litterally override a constructor, however you can add statements at the beginning of it, so your use case can be covered. This is called an initializer. See https://doc.metalama.net/conceptual/aspects/advising/initializers.