当前位置:网站首页>重载,重写的区别,抽象类,接口的区别
重载,重写的区别,抽象类,接口的区别
2022-06-28 05:55:00 【不会code的coder】
重载:
让类以统一的方式处理不同类型数据的一种手段。多个同名函数同时存在,根据传入的数据个数及类型判断使用哪种方法。
是多态性的一种体现,其多态性体现在根据传入数据个数及类型判断使用哪个方法。
特性:方法名相同,参数列表类型或者个数不同,同返回值无关。就是不同返回值的两个方法,在同一个类中是不被认为是重载,而是会产生编译错误。
重写:
父类与子类之间的多态性,对父类的函数进行重新定义。即在子类中定义某方法与其父类有相同的名称和参数。
若子类中的方法与父类中的某一方法具有相同的方法名、返回类型和参数表,则新方法将覆盖原有的方法。如需父类中原有的方法,可使用super关键字,该关键字引用了当前类的父类。
抽象类和接口的区别:
1.抽象类仍然是类的一种,有构造方法,只能单继承。是对事物的抽象,包含了属性和行为,即可以有非抽象方法和成员变量。
2.接口中只能有抽象方法,不能实例化,可以被实现。
边栏推荐
猜你喜欢

Openharmony gnawing paper growth plan -- json-rpc

Oracle基础知识总结

jq图片放大器

Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance

The windows environment redis uses AOF persistence and cannot generate an AOF file. After generation, the content of the AOF file cannot be loaded

Apple MDM Bypass 免越狱绕过MDM配置锁 免费

ES9023音频解码芯片的工作原理

Independent station sellers are using the five e-mail marketing skills, do you know?

上海域格ASR CAT1 4g模块2路保活低功耗4G应用

How to add live chat in your Shopify store?
随机推荐
Drop down box for implementation
ipvs 导致syn 重传问题
小球弹弹乐
bash install.sh ********错误
Relevant implementation records of CSI and local disk
YYGH-6-微信登录
Mosaic data enhanced mosaic
The windows environment redis uses AOF persistence and cannot generate an AOF file. After generation, the content of the AOF file cannot be loaded
Solution of dam safety automatic monitoring system for medium and small reservoirs
Oracle fundamentals summary
联想混合云Lenovo xCloud,新企业IT服务门户
数据仓库:金融/银行业主题层划分方案
猿粉猿动力-开发者活动袭!
Data middle office: an article that takes you to understand data middle office in simple terms
开发者的时代红利在哪里?
容量调度绝对值配置队列使用与避坑
V4l2 driver layer analysis
A full set of excellent SEO tutorials worth 300 yuan [159 lessons]
Office is being updated and the application cannot start normally
Qtcanpool q05: no border