当前位置:网站首页>抽象类名作为形参和返回值
抽象类名作为形参和返回值
2022-07-21 11:09:00 【编程奥特曼.】
package itheima_02;
public abstract class Animal {
public abstract void eat();
}
package itheima_02;
public class AnimalOperator {
public void useAnimal(Animal a){
//Animal a = new Cat();
a.eat();
}
public Animal getAnimal(){
Animal a = new Cat();
return a;
}
}
package itheima_02;
public class Cat extends Animal{
@Override
public void eat() {
System.out.println("猫吃鱼");
}
}
package itheima_02;
/*
测试类
*/
public class AnimalDemo {
public static void main(String[] args) {
//创建操作类对象,并调用方法
AnimalOperator ao = new AnimalOperator();
Animal a = new Cat();
ao.useAnimal(a);
Animal a2 = ao.getAnimal(); //new Cat()
a2.eat();
}
}
边栏推荐
- 2022年7月31日DAMA-CDGA/CDGP数据治理认证班开启!
- 编译原理实验1——词法分析程序设计原理与实现
- How to make the demand unable to go online smoothly as scheduled (V) business acceptance stage
- Yan's plug 'n' play feature
- Intel汇编程序设计-整数算术指令(上)
- 浅谈 Service Worker 在缓存资源以及Web Push上的应用
- 洛谷-换教室-(概率期望+dp)
- ANSVC无功补偿装置助力江苏某环保能源项目
- 记一次去除连接数限制问题
- What is REITs? Excuse me, is it safe to open a stock account by mobile phone?
猜你喜欢
Intel assembler programming - integer arithmetic instructions (Part 1)
[译] PostgreSQL 怎么决定PG 的备份策略
【2022年中总结】我走得很慢,但我从不后退
编译原理实验1——词法分析程序设计原理与实现
CLion配置WSL工具链
Run busybox, buildroot, loognix, qt5.12 system for Godson development board process
How to make the full-color LED display screen energy-saving and environmental protection?
A trick to teach you how to master online videos
PostgreSQL初/中/高级认证考试(7.16)通过考生公示
Multimodal model clip4clip takes you to realize mutual search between text and video
随机推荐
OneManager与CloudFlare Workers部署安装-绑定域名和使用CloudFlare CDN加速
yii2渲染自定义模板文件
第93篇 合约间调用(二)
Part 109 liquid in compound
迅为龙芯开发板流程运行busybox,buildroot,loognix,QT5.12系统
zooInspector下载
进程池及回掉函数[通俗易懂]
Ansvc reactive power compensation device helps an environmental protection energy project in Jiangsu
CLion配置WSL工具链
What is REITs? Excuse me, is it safe to open a stock account by mobile phone?
flash多开
ANSVC无功补偿装置助力江苏某环保能源项目
第94篇 合约间调用(三)
将一张图片以自己输入文字方式组成
第104篇 Compound 中的 cTokens
How to make the full-color LED display screen energy-saving and environmental protection?
记一次去除连接数限制问题
How to make the demand unable to go online smoothly as scheduled (III) development stage
Advanced Fruits(公共子序列)
PostgreSQL初/中/高级认证考试(7.16)通过考生公示