当前位置:网站首页>尚硅谷 p290 多态性练习
尚硅谷 p290 多态性练习
2022-04-23 05:40:00 【一蓑烟雨渡平生】
package p290;
class Base{
int count = 10;
public void display(){
System.out.println(this.count);
}
}
class Sub extends Base{
int count = 20;
public void display(){
System.out.println(this.count);
}
}
public class FieldMethodTest {
public static void main(String[] args){
Sub s = new Sub();
System.out.println(s.count); //20
s.display(); //20
Base b = s; //多态性
//引用数据类型,比较的是地址值是否相同
System.out.println(b == s); //true
System.out.println(b.count); //10
//调用子类重写的方法
b.display(); //20
}
}
版权声明
本文为[一蓑烟雨渡平生]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41894176/article/details/123193166
边栏推荐
- acwing854. Floyd finds the shortest path
- 实体中list属性为空或者null,设置为空数组
- Strategy for improving the conversion rate of independent stations | recovering abandoned users
- Reading notes of modern methods of C language programming
- POI exports to excel, and the same row of data is automatically merged into cells
- Map对象 map.get(key)
- STL function library
- freemark中插入图片
- 50 SQL exercises, answers and detailed analysis
- Error 2003 (HY000) when Windows connects MySQL: can't connect to MySQL server on 'localhost' (10061)
猜你喜欢

Transposed convolution

deep learning object detection

C语言——恶搞关机小程序

Sea Level Anomaly 和 Sea Surface Height Anomaly 的区别

Jiugong magic square - the 8th Lanqiao provincial competition - group C (DFS and comparison of all magic square types)

Flutter nouvelle génération de rendu graphique Impeller

uni使用的一些坑

Hongji micro classroom | cyclone RPA's "flexible digital employee" actuator

MySQL的锁机制

Duplicate key update in MySQL
随机推荐
Flutter 新一代图形渲染器 Impeller
弘玑|数字化时代下,HR如何进行自我变革和组织变革?
Object to map
Dwsurvey is an open source questionnaire system. Solve the problem that cannot be run and modify the bug.
The list attribute in the entity is empty or null, and is set to an empty array
poi导出excel,行相同数据自动合并单元格
Typescript interface & type rough understanding
Cmake basic tutorial (39) pkgconfig
Frequently asked interview questions - 1 (non technical)
mysql实现主从复制/主从同步
TypeScript interface & type 粗略理解
uni使用的一些坑
转置卷积(Transposed Convolution)
数据安全入门产品——数据库审计系统详解
OSI层常用协议
POI generates excel and inserts pictures
POI exports to excel, and the same row of data is automatically merged into cells
CMake基础教程(39)pkgconfig
7-10 longest symmetric substring (25 points) (violence problem solution) C language
The address value indicated by the pointer and the value of the object indicated by the pointer (learning notes)