当前位置:网站首页>The upward and downward transformation of polymorphism
The upward and downward transformation of polymorphism
2022-07-03 12:44:00 【Persia_ Pepper】
The program has been written with Animal Class and Pig class , among Animal Class only shout Method
Save the information as follows
Memory analysis
If you have to access the rest of the methods 、 attribute
public class Demo {
// This is a main Method , It's the entrance to the program :
public static void main(String[] args) {
Pig p = new Pig();
Animal an = p;// The transformation of : Upward transformation
an.shout();
// Add transformation code :
// take Animal To Pig type :
Pig pig = (Pig)an ;// The transformation of : Move down
pig.eat();
pig.age = 10;
pig.weight = 60.8;
}
}
Corresponding to the memory
Before thinking equals Method
边栏推荐
- Oh my Zsh + TMUX installation
- Swift5.7 extend some to generic parameters
- 雲計算未來 — 雲原生
- 4. Wireless in vivo nano network: electromagnetic propagation model and key points of sensor deployment
- Xctf mobile--app1 problem solving
- Is it OK to open an account for online stock speculation? Is the fund safe?
- 4. 无线体内纳米网:电磁传播模型和传感器部署要点
- 1-2 project technology selection and structure
- Powerful avatar making artifact wechat applet
- Using swift language features, write a pseudo-random number generator casually
猜你喜欢
Sword finger offer04 Search in two-dimensional array [medium]
If you can't learn, you have to learn. Jetpack compose writes an im app (II)
Self made pop-up input box, input text, and click to complete the event.
GaN图腾柱无桥 Boost PFC(单相)七-PFC占空比前馈
What is more elegant for flutter to log out and confirm again?
Record your vulnhub breakthrough record
记录自己vulnhub闯关记录
社交社区论坛APP超高颜值UI界面
ncnn神经网络计算框架在香橙派OrangePi 3 LTS开发板中的使用介绍
剑指Offer06. 从尾到头打印链表
随机推荐
Applet wxss introduction
最新版抽奖盲盒运营版
Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
The latest version of blind box mall thinkphp+uniapp
Use of atomicinteger
Using swift language features, write a pseudo-random number generator casually
Kubectl_ Command experience set
OpenStack节点地址改变
Swift Error Handling
T430 toss and install OS majave 10.14
Redhat5 installing socket5 proxy server
Sword finger offer07 Rebuild binary tree
Sword finger offer09 Implementing queues with two stacks
Apache Mina开发手册
Lambda表达式
Is it OK to open an account for online stock speculation? Is the fund safe?
Sword finger offer06 Print linked list from end to end
阿里大于发送短信(用户微服务--消息微服务)
The best shortcut is no shortcut
Ali & ant self developed IDE