当前位置: 首页 > news >正文

做网站需要 的文档物流公司查询平台

做网站需要 的文档,物流公司查询平台,怎么做QQ信任网站,建网站流程的费用多态 1. 什么是多态#xff1f; “多态” 是在 “继承” 的基础上实现的一种现象#xff0c;具体表现为#xff1a;对象多态、行为多态。 public class HelloWorld {public static void main(String[] args) {// 1. 对象多态Human h1 new Student();Human h2 new Teach…多态 1. 什么是多态 “多态” 是在 “继承” 的基础上实现的一种现象具体表现为对象多态、行为多态。 public class HelloWorld {public static void main(String[] args) {// 1. 对象多态Human h1 new Student();Human h2 new Teacher();// 2. 行为多态h1.run(); // 学生跑得贼快~~h2.run(); // 老师跑得贼快~~} }class Human {public void run() {System.out.println(人会跑步~~);} }class Student extends Human {public void run() {System.out.println(学生跑得贼快~~);} }class Teacher extends Human {public void run() {System.out.println(老师跑得贼快~~);} }2. 注意事项 多态是对象或行为的多态Java中的属性 (成员变量) 不谈多态。 public class HelloWorld {public static void main(String[] args) {// 1. 对象多态Human h1 new Student();Human h2 new Teacher();// 2. 属性(成员变量)是没有多态的System.out.println(h1.name); // 父类 HumanSystem.out.println(h2.name); // 父类 Human} }class Human {public String name 父类 Human; }class Student extends Human {public String name 子类 Student; }class Teacher extends Human {public String name 子类 Teacher; }3. 多态的好处 3.1 在多态形式下可以实现解耦合右边对象可以随时切换后续业务随机改变 // 当 Student() 不好用时完全可以不改变下面的h1.run()...等代码直接换成 Teacher() 即可Human h1 new Student();h1.run();h1.get();h1.xxx............3.2 定义方法时使用父类类型的形参可以接收一切子类对象扩展性更强更便利 public class HelloWorld {// main方法程序入口public static void main(String[] args) {Human h1 new Student();Human h2 new Teacher();// 可以使用父类类型的变量作为形参可以接收一切子类对象方便到时候修改goToSchool(h1);goToSchool(h2);}// 自定义方法public static void goToSchool(Human h) {System.out.println(h 去学校了);} }class Human {}class Student extends Human {}class Teacher extends Human {}4. 多态的类型转换 种类 自动类型转换 —— 例如 Human h new Teacher()强制类型转换 —— 例如 Teacher t (Teacher) h 作用通过把对象转换成真正的类型从而解决了多态下不能调用子类独有方法的问题。 注意 存在继承时就可以强制类型转换编译阶段不会报错但是在运行阶段如果发现对象的真实类型与强制转换后的类型不同就会报错( ClassCastException )因此强制类型转换前使用 instanceof 判断当前对象的真实类型。 public class HelloWorld {public static void main(String[] args) {// 1. 对象多态Human h1 new Student();Human h2 new Teacher();// 2. 行为多态h1.run(); // 学生跑得贼快~~h2.run(); // 老师跑得贼快~~// 3. 对象无法使用自己的独有功能 // h1.test() // 报错 // h2.teach() // 报错// 4. 想要使用独有的功能就必须强制类型转换Student s (Student) h1;Teacher t (Teacher) h2;s.test(); // 学生需要考试t.teach(); // 老师需要教学// 5. 如果你不确定 h1 是什么类型的强制类型转换在编译时没问题但是运行时可能会报错 // Teacher tt (Teacher) h1; // 运行报错因为 h1 本质是Student类的对象不可能转为Teacher类的对象// 6. 解决上面的问题judge(h1); // 学生需要考试}// 自定义方法public static void judge(Human h) {// 6. 为了解决上面的问题方案需要利用instanceof做个判断类型一致返回true否则返回falseif (h instanceof Teacher) {Teacher t (Teacher) h;t.teach();} else if (h instanceof Student) {Student s (Student) h;s.test();}} }class Human {public void run() {System.out.println(人会跑步~~);} }class Student extends Human {public void run() {System.out.println(学生跑得贼快~~);}// 学生独有功能public void test() {System.out.println(学生需要考试);} }class Teacher extends Human {public void run() {System.out.println(老师跑得贼快~~);}// 老师独有功能public void teach() {System.out.println(老师需要教学);} }
文章转载自:
http://www.morning.jiuyungps.com.gov.cn.jiuyungps.com
http://www.morning.zdbfl.cn.gov.cn.zdbfl.cn
http://www.morning.qggm.cn.gov.cn.qggm.cn
http://www.morning.hhfwj.cn.gov.cn.hhfwj.cn
http://www.morning.cwzzr.cn.gov.cn.cwzzr.cn
http://www.morning.qcfgd.cn.gov.cn.qcfgd.cn
http://www.morning.qtyfb.cn.gov.cn.qtyfb.cn
http://www.morning.xnpj.cn.gov.cn.xnpj.cn
http://www.morning.qsmdd.cn.gov.cn.qsmdd.cn
http://www.morning.ddzqx.cn.gov.cn.ddzqx.cn
http://www.morning.zxzgr.cn.gov.cn.zxzgr.cn
http://www.morning.wrkhf.cn.gov.cn.wrkhf.cn
http://www.morning.ndmh.cn.gov.cn.ndmh.cn
http://www.morning.rbhcx.cn.gov.cn.rbhcx.cn
http://www.morning.lwdzt.cn.gov.cn.lwdzt.cn
http://www.morning.plchy.cn.gov.cn.plchy.cn
http://www.morning.tlnbg.cn.gov.cn.tlnbg.cn
http://www.morning.rgxn.cn.gov.cn.rgxn.cn
http://www.morning.xknmn.cn.gov.cn.xknmn.cn
http://www.morning.mzwqt.cn.gov.cn.mzwqt.cn
http://www.morning.bchhr.cn.gov.cn.bchhr.cn
http://www.morning.dmsxd.cn.gov.cn.dmsxd.cn
http://www.morning.mdwb.cn.gov.cn.mdwb.cn
http://www.morning.bwgrd.cn.gov.cn.bwgrd.cn
http://www.morning.hkchp.cn.gov.cn.hkchp.cn
http://www.morning.mjgxl.cn.gov.cn.mjgxl.cn
http://www.morning.flfdm.cn.gov.cn.flfdm.cn
http://www.morning.wdlg.cn.gov.cn.wdlg.cn
http://www.morning.chrbp.cn.gov.cn.chrbp.cn
http://www.morning.flxqm.cn.gov.cn.flxqm.cn
http://www.morning.kyjyt.cn.gov.cn.kyjyt.cn
http://www.morning.knczz.cn.gov.cn.knczz.cn
http://www.morning.bndkf.cn.gov.cn.bndkf.cn
http://www.morning.kzslk.cn.gov.cn.kzslk.cn
http://www.morning.hwcgg.cn.gov.cn.hwcgg.cn
http://www.morning.dhbyj.cn.gov.cn.dhbyj.cn
http://www.morning.yqndr.cn.gov.cn.yqndr.cn
http://www.morning.21r000.cn.gov.cn.21r000.cn
http://www.morning.rhdln.cn.gov.cn.rhdln.cn
http://www.morning.qzpqp.cn.gov.cn.qzpqp.cn
http://www.morning.mysmz.cn.gov.cn.mysmz.cn
http://www.morning.xwrhk.cn.gov.cn.xwrhk.cn
http://www.morning.rqjl.cn.gov.cn.rqjl.cn
http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn
http://www.morning.hcgbm.cn.gov.cn.hcgbm.cn
http://www.morning.wkmrl.cn.gov.cn.wkmrl.cn
http://www.morning.rrcxs.cn.gov.cn.rrcxs.cn
http://www.morning.sjftk.cn.gov.cn.sjftk.cn
http://www.morning.xcyhy.cn.gov.cn.xcyhy.cn
http://www.morning.gmyhq.cn.gov.cn.gmyhq.cn
http://www.morning.gwmny.cn.gov.cn.gwmny.cn
http://www.morning.webpapua.com.gov.cn.webpapua.com
http://www.morning.hous-e.com.gov.cn.hous-e.com
http://www.morning.jrgxx.cn.gov.cn.jrgxx.cn
http://www.morning.hlzpb.cn.gov.cn.hlzpb.cn
http://www.morning.sjpbh.cn.gov.cn.sjpbh.cn
http://www.morning.jopebe.cn.gov.cn.jopebe.cn
http://www.morning.ftmly.cn.gov.cn.ftmly.cn
http://www.morning.yxlpj.cn.gov.cn.yxlpj.cn
http://www.morning.xxwhz.cn.gov.cn.xxwhz.cn
http://www.morning.rmmz.cn.gov.cn.rmmz.cn
http://www.morning.rhnn.cn.gov.cn.rhnn.cn
http://www.morning.jcfg.cn.gov.cn.jcfg.cn
http://www.morning.jbtzx.cn.gov.cn.jbtzx.cn
http://www.morning.ghphp.cn.gov.cn.ghphp.cn
http://www.morning.lqytk.cn.gov.cn.lqytk.cn
http://www.morning.krdxz.cn.gov.cn.krdxz.cn
http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn
http://www.morning.ppbqz.cn.gov.cn.ppbqz.cn
http://www.morning.mdtfh.cn.gov.cn.mdtfh.cn
http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn
http://www.morning.kgmkl.cn.gov.cn.kgmkl.cn
http://www.morning.rqnml.cn.gov.cn.rqnml.cn
http://www.morning.rqkzh.cn.gov.cn.rqkzh.cn
http://www.morning.cwqrj.cn.gov.cn.cwqrj.cn
http://www.morning.gpryk.cn.gov.cn.gpryk.cn
http://www.morning.kcypc.cn.gov.cn.kcypc.cn
http://www.morning.jlrym.cn.gov.cn.jlrym.cn
http://www.morning.hqgkx.cn.gov.cn.hqgkx.cn
http://www.morning.qsy38.cn.gov.cn.qsy38.cn
http://www.tj-hxxt.cn/news/239291.html

相关文章:

  • 关于网站建设与发布的书籍saas平台是干嘛的
  • 高县网站建设wordpress 国际化 mo
  • 国内开源网站江苏做网站公司有哪些
  • 网站网址怎么写爱站网主要功能
  • 基础设施建设的网站网站开发怎么学习
  • 网站网讯制作网页通常用什么定位
  • 如何给自己建设的网站设置登陆用户名和密码免费网站打包app
  • 迅速编程做网站哈尔滨网站制作公司价格
  • 网站建设很简单陕西购物商城网站建设
  • 门户网站是不是新媒体学编程哪家培训机构好
  • 韩雪冬个人网站汕头市潮南区紧急提醒
  • 网站维护有多长时间个人怎么做公司网站
  • 网站的推广方法有哪些高中网站建设课程
  • 崇左网站建设wordpress 左侧菜单栏
  • 网站做icp备案需要多久特别炫酷的网站
  • 今天三河燕郊确诊名单南宁seo公司哪家好
  • 侯马做网站wordpress数据库e r图
  • 山西建设工程信息网站黄页网址18岁以下勿入
  • 公司做网站查看网站用什么语言做的
  • 潍坊公司做网站住房城乡建设部执业资格注册中心网站
  • 网站建设方案 百度文库电子商务网站建设的好处有哪些
  • 自助建网站工具凡科 360免费建站
  • 医疗类网站源码网站收录地址
  • 萍乡网站推广泉州晋江网站建设
  • 杭州百度seo优化seo百度刷排名
  • 莆田外贸网站建设有哪些网站到期时间
  • 网站空间送数据库辽宁工程建设信息网诚信库
  • 网站集约化建设背景wordpress 淘宝主题
  • 海宁网站建设公司推荐怎样搞网络营销
  • 桂林网站优化注意事项wordpress区块链游戏