当前位置:网站首页>2022-07-21 group 4 polymorphism
2022-07-21 group 4 polymorphism
2022-07-26 03:14:00 【Self cultivation class】
Polymorphic basic syntax :
1、 Before learning basic grammar , Two concepts need to be popularized :
Upward transformation
Son ----> Father
Move down
Father ----> Son
java Allow upward transformation in , It also allows downward transformation .
Whether it's up or down , There must be an inheritance relationship between the two types , No inheritance , The compiler will report an error
Polymorphism refers to :
A parent type reference points to a child type object
Including compile phase and run phase
Compile phase : Method of binding parent class
Operation phase : Methods for dynamically binding subtype objects ·
In many forms
Parent type Variable name =new Subclass object ;
Variable name . Method name ();
Parent type : Refers to the type of parent class inherited by the child class object , Or the interface type of the parent class of the implementation
When a method is invoked in a polymorphic manner , First check that the method is present in the parent class , without , Compile error ; If there is , What is executed is the method after subclass rewriting
Reference type conversion
Upward transformation : Polymorphism itself is the process of up conversion from subclass type to parent type , This process is the default . When a parent reference points to a subclass object , It's the upward transformation .
Parent type Variable name =new Subclass type ();
Such as :Animal a=new Cat();Move down : The process of converting a parent type down to a child type , This process is mandatory , A subclass object that has been transformed upward , Convert a parent class reference to a child class reference , You can use the cast format , It's a downward shift
When you need to access subclass objects " specific " Methods , At this time, it must be a downward transformation .
Subclass type Variable name =new ( Subclass type ) Parent variable
Such as :Cat c=new (Cat)a;Abnormal transformation
Animal a=new Cat();
a.eat();// It's called Cat Of eat
Dog d=new (Dog)a;
d.run();// It's called Dog Of run, Operation error reporting This is because Cat and Dog There is no inheritance , Does not meet the definition of type conversion
instranceof
If the variable belongs to this data type, return true
If the variable does not belong to the data type, return false
Animal a=new Cat();
a.eat;
if(a instanceof Cat){
Cat c=new (Cat)a;
c.run();
}else if(a instanceof Dog){
Dog d=new (Dog)a;
d.run();
}Anonymous object
Most of them are used to transmit parameters
Anonymous objects are used with constructors
grammar :
new Class name ();
function : It has the same function as normal named objects . It still has the call attribute , Function of method .
Use scenarios : Most of them are used in parameter transmission , Actual parameters , In most cases, it is used with constructors
benefits : Saving resource
Arrays class , Array tool class
Is an array a class :
- Standing on the JVM From the perspective of , It's a class , stay JVM When parsing an array , Will generate an array of parsing arrays
- From the perspective of compilation , Not class , Because there is no class name , There is no structure .
Linked list : It's a data structure
There is no subscript in the linked list
In memory , Arrays and linked lists are the most basic data structures , surface , Or linear table .
The linear table , Linear structure , It is one containing n>=0 A finite sequence of nodes , There is only one previous node , There is also a next node . A line with ends
One way linked list : While maintaining the value of a node itself , Also maintain the direction of its next value
Double linked list : While maintaining the value of a node itself , Also maintain the direction of its previous and next values
ArrayList and LinkedList What's the difference? ?
The disadvantages and advantages of arrays :
shortcoming : Too complex space
advantage : Easy to query and modify
What are the disadvantages and advantages of linked lists .
边栏推荐
- 【C进阶】深入探索数据的存储(深度剖析+典例解读)
- Canvas -- drawing of rectangle -- making of histogram
- els 注册窗口类、创建窗口类、显示窗口
- OxyCon 2022 网络抓取前沿大会即将开启!
- Influence of middle tap change on ZVS oscillation circuit
- [SQL] CASE表达式
- Is the galaxy VIP account opened by qiniu safe?
- Get twice the result with half the effort: learn the web performance test case design model
- (九)属性自省
- The source of everything, the choice of code branching strategy
猜你喜欢

Implement a method to find the sum of the number k and m in the array

Course notes of single chip microcomputer principle and interface technology for migrant workers majoring in electronic information engineering
![[SQL] 自连接的用法](/img/92/92474343b4b4e6ea60453b4799cb55.jpg)
[SQL] 自连接的用法

FPGA_Vivado软件初次使用流程_超详细

中国信通院陈屹力:降本增效是企业云原生应用的最大价值

FPGA_ Initial use process of vivado software_ Ultra detailed

Oxycon 2022 network capture frontier conference is about to open!

班级里有一群学生考试结果出来了,考了语文和数学两门,请筛选出总分是第一的同学

Unknown-Aware Object Detection:Learning What You Don’t Know from Videos in the Wild(CVPR 2022)

Digital commerce cloud DMS dealer management system solution: DMS system realizes business Omni channel and sales data collection
随机推荐
规范自己debug的流程
中国信通院陈屹力:降本增效是企业云原生应用的最大价值
Cloud native guide what is cloud native infrastructure
Canvas -- drawing of rectangle -- making of histogram
YOLOv3: An Incremental Improvement
堆内存与栈内存的区别?
Leetcode · daily question · 919. complete binary tree inserter · hierarchy traversal · BFS
使用anaconda配置gpu版本的tensorflow(30系列以下显卡)
手把手教你依赖管理
An article allows you to understand the relevance of cloud native containerization
Digital commerce cloud DMS dealer management system solution: DMS system realizes business Omni channel and sales data collection
Service gateway (zuul)
els 消息循环
FPGA_Vivado软件初次使用流程_超详细
[SQL] CASE表达式
There are a group of students in the class who have got the test results in Chinese and mathematics. Please select the students whose total score is the first
经典面试问题——OOP语言的三大特征
hello world驱动(二)-初级版
Multithreaded programming
[NOIP2001 普及组]装箱问题