当前位置:网站首页>Polymorphism, final and interface
Polymorphism, final and interface
2022-07-26 07:32:00 【Mourning】
polymorphic : Multiple states ( Different states at different times )
Necessary condition :
- Have inherited , A parent class can represent a subclass .
- There's rewriting ( Refers specifically to abstract methods ), After rewriting , Call subclass overridden methods .
- The parent class reference points to the subclass object .
- In polymorphism , Compile to the left , Run to the right .
Be careful :
- For static methods , Both compilation and operation are on the left .
- For member variables , Both compilation and operation are on the left .
The transformation of :
Upward transformation :
Animal1 animal = new Bird1();
animal.eat();Move down :
Animal1 animal = new Bird1();
Bird1 bird=(Bird1)animal; Polymorphic deficiency : A parent type cannot access methods unique to a child class .
final:
final Keywords represent the final 、 Unalterable . There are four common uses : 1. Can be used to modify a class 2. Can be used to modify a method 3. It can also be used to modify a local variable 4. It can also be used to modify a member variable
- final Used to declare properties , Methods and classes .
- attribute : The definition must be assigned directly or in the construction method , And later can'tmodify .
- Method : Subclasses cannot be overridden
- class : Cannot be defined as an abstract class or interface , Not to be inherited .
abstract 、 Common points of interfaces :
- It's all an abstraction
- Can't be instantiated
- Are used to be inherited and implemented by other classes
abstract 、 Interface differences :
abstract class : You can define member variables , Methods can be constructed directly , You can define non Abstract member methods ( Contains abstract methods , Cannot create object )
Interface : Define constants 、 Abstract method 、 static state 、 The default method 、 Cannot have constructor in interface , Interfaces can inherit multiple interfaces .
边栏推荐
- Interview question set
- NFT digital collection development: digital collections help enterprise development
- What is message subscription and publishing?
- DADNN: Multi-Scene CTR Prediction via Domain-Aware Deep Neural Network
- NFT digital collection system development: activating digital cultural heritage
- NFT数字藏品系统开发:华为发布首款珍藏版数字藏品
- JWT quick start
- 2019 ZTE touyue · model compression scheme
- 3.0.0 alpha blockbuster release! Nine new functions and new UI unlock new capabilities of dispatching system
- How to ensure the double write consistency between cache and database?
猜你喜欢

【每日一题】919. 完全二叉树插入器

How to ensure the double write consistency between cache and database?

From boosting to lamdamart

机器学习相关比赛网站

NFT digital collection system development: the collision of literature + Digital Collections

数据库基础

正则表达式规则以及常用的正则表达式

HCIP---BGP综合实验

Compose Canvas line chart
![PostgreSQL UUID fuzzy search UUID string type conversion SQL error [42883] explicit type casts](/img/ba/28afaead68c9ff47d15d5c5395d9ce.png)
PostgreSQL UUID fuzzy search UUID string type conversion SQL error [42883] explicit type casts
随机推荐
Next item recommendations in short sessions
从Boosting谈到LamdaMART
PXE高效批量网络装机
Practice of online question feedback module (XIV): realize online question answering function
C# 使用Log4Net记录日志(基础篇)
The analysis, solution and development of the problem of router dropping frequently
TensorFlow学习日记之tflearn
什么是消息订阅和发布?
3.0.0 alpha blockbuster release! Nine new functions and new UI unlock new capabilities of dispatching system
Hcip--- BGP comprehensive experiment
ARIMA model for time series analysis and prediction
Oauth2.0 series blog tutorial summary
Compose canvas custom circular progress bar
System architecture & microservices
Wrong Addition
Configure flask
此章节用于补充
Meta universe infrastructure: analysis of the advantages of Web 3.0 chain33
Apache dolphin scheduler 2.x nanny level source code analysis, China Mobile engineers uncover the whole process of service scheduling and start
PXE efficient batch network installation