class Base {
public static void display() {
System.out.println("Static or class method from Base");
}
public void print() {
System.out.println("Non-static or Instance method from Base");
}
}
class Derived extends Base {
public static void display() {
System.out.println("Static or class method from Derived");
}
public void print() {
System.out.println("Non-static or Instance method from Derived");
}
}
// Driver class
public class Test {
public static void main(String args[]) {
Base obj1 = new Derived();
obj1.display();
obj1.print();
}
}
此代码的输出显示 -
Static or class method from Base
Non-static or Instance method from Derived
任何人都可以解释我为什么会这样?