Here is a short example from the JLS 8.4.8.2 section.
class Super {
static String greeting() { return "Goodnight"; }
String name() { return "Richard"; }
}
class Sub extends Super {
static String greeting() { return "Hello"; }
String name() { return "Dick"; }
}
class Test {
public static void main(String[] args) {
Super s = new Sub();
System.out.println(s.greeting() + ", " + s.name());
}
}
According to the discussion of the example, the output of the work main()will be "Goodnight, Dick." This is because static methods are called based on the static type of the called variable / expression.
: , , s , Sub, , , , . ? Java , -, - ?