Задача не проходила пока в двух методах initialize не проставил инициализацию , но не во всех пяти.
this.color ="red";
this.address = null;
Немного не понял , объясните, Когда нужно инициализировать все переменные? в первой инициализации и в той что с максимальным количеством параметров? или по другому принципу?
public class Cat {
public String name ;
public int age;
public int weight;
public String address;
public String color;
public void initialize(String name){
this.name = name;
this.age = 3;
this.weight = 5;
this.color ="red";
this.address = null;
}
public void initialize(String name, int weight, int age){
this.name = name;
this.age = age;
this.weight = weight;
this.color ="red";
this.address = null;
} public void initialize(String name, int age){
this.name = name;
this.age = age;
this.weight = 5;
this.color = null;
}
public void initialize(int weight, String color){
this.age = 3;
this.weight = weight;
this.color = color;
}
public void initialize(int weight, String color, String address) {
this.age = 3;
this.weight = weight;
this.color = color;
this.address = address;
}
public static void main(String[] args) {
Cat cat = new Cat();
cat.initialize("кот");
System.out.println(cat.name);
}
}