我想在牛奶类中设置名称和代码静态属性。为什么这不起作用?我什至不能覆盖名称和代码的设置器/获取器。
public abstract class Cow {
private static String name;
private static String code;
...
public static String getName() {
return name;
}
public static void setName(String name) {
Cow.name = name;
}
public static String getCode() {
return code;
}
public static void setCode(String code) {
Cow.code = code;
}
...
}
public class Milk extends Cow{
...
static {
Milk.setName("asdmilk");
Milk.setCode("KDDFA");
}
..
}