Answer the question
In order to leave comments, you need to log in
Static members don't copy their data even in descendants?
class A {
public static int i = 10;
public static void printI() {
System.out.println(i);
}
}
class B extends A {
public static void changeI() {
i++;
}
}
public class Main {
public static void main(String[] args) {
A a = new A();
B b = new B();
a.printI();
b.printI();
b.changeI();
a.printI();
b.printI();
}
}
Answer the question
In order to leave comments, you need to log in
Static members are not inherited, right. Because it's pointless.
I just thought why is it needed in enum valueOf(). Understood. I assumed that the method stores the string representation of the constants, and then compares the input data with them.
public enum Hello {
FIZZ, BUZZ;
// Данный метод автоматически генерируется компилятором.
// Для любого enum'а.
public static Hello valueOf(String name) {
return Enum.valueOf(Hello.class, name);
}
}
But since I know that enum constants are anonymous classes
It turns out that I really have to override these variables with a repeated declaration to break the connection with the ancestor?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question