Static methods should be available with the class name, not an object reference. The correct equivalent of what you wrote:
System.out.println(Tenor.sing() + " " + Singer.sing())
Java is to guess the conclusion about which method you should call based on type object .
EDIT: As Stephen remarked, this is not a guess. The conclusion is likely to be a more accurate word. I was just trying to emphasize that calling static functions in object references can lead to behavior you don't expect. In fact, I just tried a few things and found out that my previous statement was wrong: Java decides which method to call based on the type of the variable. This is obvious now, when I think about it more, but I see how this can lead to confusion if you did something like:
Singer s = new Tenor(); System.out.println(s.sing());
takteek
source share