Why do these two code samples produce different outputs?

后端 未结 5 1048
离开以前
离开以前 2021-01-18 02:57

Sample 1:

 class Animal {
     public static void saySomething() { System.out.print(\" Gurrr!\"); 
   }
 }
 class Cow extends Animal {
    public static void         


        
5条回答
  •  忘掉有多难
    2021-01-18 03:22

    You cannot override static methods with the same signature in subclasses, just hide them.

    For class methods, the runtime system invokes the method defined in the compile-time type of the reference on which the method is called. For instance methods, the runtime system invokes the method defined in the runtime type of the reference on which the method is called.

    http://life.csu.edu.au/java-tut/java/javaOO/override.html

提交回复
热议问题