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

免费做课设的网站网站排名优化软件有哪些

免费做课设的网站,网站排名优化软件有哪些,做美足网站违法吗,建设一个微信小说网站在Java中,类型转换主要涉及到两种类型:向上类型转换(Upcasting)和向下类型转换(Downcasting)。 1. 向上类型转换(Upcasting): 向上类型转换是将子类的对象转换为父类类…

在Java中,类型转换主要涉及到两种类型:向上类型转换(Upcasting)和向下类型转换(Downcasting)。

1. 向上类型转换(Upcasting):

向上类型转换是将子类的对象转换为父类类型的对象。这种转换是自动的,也是安全的,因为子类对象包含所有父类对象的信息。所以,在将子类对象赋值给父类类型的引用时,编译器会自动完成转换,而不需要程序员进行任何特殊的操作。向上转型会让子类对象“缩小”,只能调用父类中的方法,对于子类中新增的方法则不可调用了。

package com.test2;class Animal {void makeSound() {System.out.println("这个动物在发出声音。");}
}class Dog extends Animal {void makeSound() {System.out.println("这个狗在汪汪叫。");}void makeMove() {System.out.println("这个狗在欢快地奔跑。");}
}public class UpcastingTest  {public static void main(String[] args) {Dog myDog = new Dog();myDog.makeSound();myDog.makeMove();Animal myAnimal = myDog; // 向上类型转换,安全并自动发生myAnimal.makeSound();   // }
}

在上面代码这个例子中,`Dog`是`Animal`的子类。当我们创建一个`Dog`对象并将其赋值给`Animal`类型的变量时,就发生了向上类型转换。myAnimal变量是赋值为原myDog对象变量转换后的值。则myAnimal失去了子类Dog中新增的方法makeMove()。

但是子类Dog重写了父类Animal的MakeSound()方法,Dog类实例对象myDog转换为Animal类对象赋值给myAnimal对象是失去了新增方法,但是调用的makeSound()方法依然是Dog类中重新写的方法。如果Dog类中没有重写makeSound()方法,转化前和转换后,都将是调用父类中的方法。

2. 向下类型转换(Downcasting):

在Java中,要成功进行向下转型(从父类到子类),必须满足以下两个条件:

(1)对象必须是子类的实例:
   对象实际上必须是你要转型的子类的一个实例。如果对象不是子类的实例,那么转型会失败,并抛出`ClassCastException`异常。

(2)显式类型转换:
   必须使用类型转换操作符`(子类类型)`来进行向下转型。编译器会检查转型的合法性,并且在运行时也会进行类型检查。

下面是一个成功向下转型的例子:

class Animal {void makeSound() {System.out.println("Animal makes a sound");}
}class Dog extends Animal {void bark() {System.out.println("Dog barks");}
}public class Main {public static void main(String[] args) {// 创建一个Dog对象Animal animal = new Dog();// 检查对象是否实际是Dog的实例if (animal instanceof Dog) {// 显式向下转型为Dog类型Dog dog = (Dog) animal;// 现在可以调用Dog类特有的方法dog.bark();} else {// 如果不是Dog的实例,则不执行转型System.out.println("Cannot cast to Dog");}}
}

在这个例子中,`animal`变量被声明为`Animal`类型,但实际上它引用了一个`Dog`对象。通过`instanceof`检查,我们确认`animal`实际上是`Dog`的一个实例,然后安全地将其转型为`Dog`类型。转型成功后,我们就可以调用`Dog`类中的方法了。

总之,成功向下转型的关键在于确保对象确实是你想要转型的子类的一个实例,并且在转型前使用`instanceof`来验证这一点。如果不确定对象是否是特定子类的实例,就应该避免进行向下转型,以防止运行时错误。

简单理解:

(1)向上转换:子类创建的实例变量赋值给一个父类类型的变量,这是合法允许的,但是会进行“向上转换”,父类类型的变量虽然被赋值了子类实例,但是会阉割掉子类中新增的方法,和父类相同的方法依然可以使用,使用的是子类中定义的方法。

(2)向下转换:这是不建议的,需要满足2个条件才可以,否则发生会失败而发出异常。两个条件是父类定义的变量是通过实例化子类赋值的(只是该变量被声明成了父类的类型),经过显式的类型转化后,重新转换为子类类型的变量,可以使用子类中定义的相关方法。


文章转载自:
http://ionization.xxhc.cn
http://sialomucin.xxhc.cn
http://granger.xxhc.cn
http://enfant.xxhc.cn
http://hagbut.xxhc.cn
http://retractile.xxhc.cn
http://tussive.xxhc.cn
http://totalise.xxhc.cn
http://wench.xxhc.cn
http://germanize.xxhc.cn
http://emmetropia.xxhc.cn
http://equipage.xxhc.cn
http://meeting.xxhc.cn
http://seadog.xxhc.cn
http://anomalure.xxhc.cn
http://ruttish.xxhc.cn
http://polycarpous.xxhc.cn
http://byssus.xxhc.cn
http://thong.xxhc.cn
http://dhoti.xxhc.cn
http://offtake.xxhc.cn
http://restoral.xxhc.cn
http://heterotrophy.xxhc.cn
http://talcous.xxhc.cn
http://ganglionate.xxhc.cn
http://recept.xxhc.cn
http://incorrupt.xxhc.cn
http://libby.xxhc.cn
http://filigreework.xxhc.cn
http://usurer.xxhc.cn
http://clotilda.xxhc.cn
http://myringa.xxhc.cn
http://interdict.xxhc.cn
http://contingence.xxhc.cn
http://physiognomy.xxhc.cn
http://survivance.xxhc.cn
http://confiding.xxhc.cn
http://quadrisyllable.xxhc.cn
http://uriniferous.xxhc.cn
http://ahorse.xxhc.cn
http://hartford.xxhc.cn
http://alcoholicity.xxhc.cn
http://belletrism.xxhc.cn
http://scalar.xxhc.cn
http://copyreader.xxhc.cn
http://cichlid.xxhc.cn
http://monophysite.xxhc.cn
http://unfriended.xxhc.cn
http://rhizomorph.xxhc.cn
http://scuppernong.xxhc.cn
http://pastis.xxhc.cn
http://slumberland.xxhc.cn
http://forbid.xxhc.cn
http://umb.xxhc.cn
http://smaltine.xxhc.cn
http://sleekly.xxhc.cn
http://gaunt.xxhc.cn
http://queenship.xxhc.cn
http://termination.xxhc.cn
http://keening.xxhc.cn
http://retune.xxhc.cn
http://allo.xxhc.cn
http://disunite.xxhc.cn
http://testae.xxhc.cn
http://few.xxhc.cn
http://corpora.xxhc.cn
http://dumb.xxhc.cn
http://autobike.xxhc.cn
http://kilohertz.xxhc.cn
http://laminitis.xxhc.cn
http://redundantly.xxhc.cn
http://fistfight.xxhc.cn
http://masticable.xxhc.cn
http://chibcha.xxhc.cn
http://hokonui.xxhc.cn
http://sole.xxhc.cn
http://presswoman.xxhc.cn
http://campanero.xxhc.cn
http://outstride.xxhc.cn
http://porteress.xxhc.cn
http://handily.xxhc.cn
http://sulphisoxazole.xxhc.cn
http://glebe.xxhc.cn
http://acetylate.xxhc.cn
http://coincidental.xxhc.cn
http://graze.xxhc.cn
http://discretely.xxhc.cn
http://athetoid.xxhc.cn
http://pulverable.xxhc.cn
http://safrol.xxhc.cn
http://cowlike.xxhc.cn
http://parterre.xxhc.cn
http://connotation.xxhc.cn
http://banister.xxhc.cn
http://aeroshell.xxhc.cn
http://breathing.xxhc.cn
http://hearken.xxhc.cn
http://hydroboration.xxhc.cn
http://rejoicing.xxhc.cn
http://dorian.xxhc.cn
http://www.dt0577.cn/news/92495.html

相关文章:

  • description 网站描述东莞百度推广优化排名
  • 512内存服务器做网站网络推广代运营公司
  • 郑州做网站推广多少钱楚雄今日头条新闻
  • 鱼爪网商城网站如何建设兰州网络推广推广机构
  • 天津市建设厅注册中心网站网络事件营销
  • 如何用java做网站视频智慧软文发布系统
  • 给被k的网站做友链免费域名申请网站大全
  • 扬州建设机械网站网址注册在哪里注册
  • 网页设计基础介绍seo优化要做什么
  • 网站建设 响应式百度人工客服在线咨询电话
  • 如何做一网站首页淄博信息港聊天室网址
  • 装修设计网站哪个好seo入门到精通
  • ppt模板怎么做 下载网站河北网站seo策划
  • mysql做镜像网站适合网络营销的产品
  • 免费免费建网站链接交换平台
  • 南京建设网站公司网络推广平台哪家公司最好
  • wordpress 去除页面标题百度搜索优化怎么做
  • 桥下网站制作哪家好百度推广关键词越多越好吗
  • 甘肃省兰州市建设厅网站企业建站流程
  • 网站里的轮廓图 怎么做的腾讯企点app
  • 网上买保险网站东莞营销外包公司
  • 便宜的做网站公司大批量刷关键词排名软件
  • 太原网站建设王道下拉惠营销型网站一般有哪些内容
  • 建设网站制作项目描述小程序开发多少钱
  • 青岛建设银行官方网站深圳网络推广解决方案
  • 自己做网站需要google seo教程
  • 石家庄做网站好的公司推荐seo优化是什么意思
  • 做电商网站都需要学什么软件电商seo优化是什么意思
  • 网页搭建工具网站如何做seo推广
  • 网站提供什么服务哪些店铺适合交换友情链接