Skip to content

Instantly share code, notes, and snippets.

@enl
Created April 6, 2016 05:04
Show Gist options
  • Save enl/dd77a03bbda2742291ddbde78887d8b2 to your computer and use it in GitHub Desktop.
Save enl/dd77a03bbda2742291ddbde78887d8b2 to your computer and use it in GitHub Desktop.
Cats constructor overload
class Color {}
class Address {}
class Cat {
private Int age;
private Double weight;
private String name;
private Address address;
private Color color;
Cat(String name) {
super(name, Cat.getDefaultWeight(), Cat.getDefaultAge())
}
Cat(String name, Double weight, Int age) {
this.name = name;
this.weight = weight;
this.age = age;
}
Cat(String name, Int age) {
super(name, Cat.getDefaultWeight(), age);
}
Cat(Color color, Double weight) {
super(null, weight, Cat.getDefaultAge());
this.color = color;
}
Cat(Color color, Double weight, Address address) {
super(color, weight);
this.address = address;
}
static Double getDefaultWeight() {
return 3.5;
}
static Int getDefaultAge() {
return 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment