java - 我们可以覆盖静态方法吗?为什么输出是这样的?
问题描述
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
谁能解释一下为什么会这样??
解决方案
推荐阅读
- php - php connect postgres sql错误你能帮我吗?
- amazon-web-services - AWS ECS 任务单实例
- makefile - 递归调用 make 中的错误不会停止调用 make
- typescript - 自定义验证器验证对象键
- clearcase - ClearTeam Explorer 联系过期的许可证主机
- python - 无法使用 Python 请求获取整个 HTML 页面
- python - Numpy中的行加法或列加法
- mysql - 获取特定列值遵循 SQL 版本 MySQL 5.5 中的条件
- python - 如何找出 set_data 的期望
- android - Android应用程序中的在线视频是应用程序购买还是服务?