当前位置:网站首页>Abstract class name as formal parameter and return value
Abstract class name as formal parameter and return value
2022-07-22 03:52:00 【Programming Altman】
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(" Cats eat fish ");
}
}
package itheima_02;
/*
Test class
*/
public class AnimalDemo {
public static void main(String[] args) {
// Create an operation class object , And call methods
AnimalOperator ao = new AnimalOperator();
Animal a = new Cat();
ao.useAnimal(a);
Animal a2 = ao.getAnimal(); //new Cat()
a2.eat();
}
}
边栏推荐
猜你喜欢
Idea 2020.1 cancel parameter name display
Compilation Principle Experiment 1 -- principle and implementation of lexical analysis program design
大型体育场馆应急照明设计
xxl-job源码阅读笔记
seaborn绘制箱线图和折线图
【2022年中总结】我走得很慢,但我从不后退
MONAI Label -- 使用 AI 加速你的分割标注
A trick to teach you how to master online videos
数据中心末端直流配电系统产品的应用
ASP. Net GridView dynamically displays hidden columns and saves the customer's configuration (user control cookie version)
随机推荐
Part 100 library contract compatible with Eth and erc20
A lesson in blood NPM package lock The bloody rain caused by JSON
初识数据库
执掌英国工程技术学会13载,范纳杰正式退休
乘数科技云管控平台适配阿里云PolarDB,共促云原生数据库生态繁荣
进程池及回掉函数[通俗易懂]
腾讯浏览器服务TBS使用
生物制药安全供电保生产
Compose a picture by inputting text by yourself
一次血的教训 记npm package-lock.json导致的腥风血雨
MONAI Label -- 使用 AI 加速你的分割标注
CyberPanel免费开源面板-高速LSCache免费SSL证书-可自建DNS和企业邮局
zooInspector下载
flash多开
抽象类名作为形参和返回值
编译原理实验1——词法分析程序设计原理与实现
Convolutional Neural Networks in TensorFlow quizs on Coursera
mysql隐藏版本号
Seckill design
C语言练习题-结构体与联合体