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

绍兴哪些公司做网站网页建设的公司

绍兴哪些公司做网站,网页建设的公司,国内十强少儿编程机构,潮流设计网站Java中#xff0c;instanceof运算符的前一个操作符是一个引用变量#xff0c;后一个操作数通常是一个类(可以是接口)#xff0c;用于判断前面的对象是否是后面的类#xff0c;或者其子类、实现类的实例。如果是返回true#xff0c;否则返回false。也就是说#xff1a;使用…Java中instanceof运算符的前一个操作符是一个引用变量后一个操作数通常是一个类(可以是接口)用于判断前面的对象是否是后面的类或者其子类、实现类的实例。如果是返回true否则返回false。也就是说使用instanceof关键字做判断时 instanceof 操作符的左右操作数必须有继承或实现关系下面我们用继承树来判断instanceof的返回值1 packageinstanceofTest;23 /**4 *authorzsh5 * company wlgzs6 * create 2019-03-21 19:557 * Describe 继承树来判断instanceof的返回值8 */9 interfaceMan{}10 class Person1 implementsMan{}11 class Student extendsPerson1{}12 class Postgraduate extendsStudent {}13 classAnimal {}14 public classMain1 {15 public static voidmain(String[] args) {16 System.out.println(Student 的对象是谁的实例);17 instanceofTest(newStudent());18 System.out.println(Animal 的对象是谁的实例);19 instanceofTest(newAnimal());20 System.out.println(Postgraduate 的对象是谁的实例);21 instanceofTest(newPostgraduate());22 //一个类的实例是这个类本身的实例也是他父类父类的父类的实例也是实现的接口的实例23 }2425 public static voidinstanceofTest(Object p) {26 if (p instanceofAnimal)27 System.out.println(p.getClass() 类的实例 是类Animal的实例);28 if (p instanceofPostgraduate)29 System.out.println(p.getClass() 类的实例 是类Postgraduate的实例);30 if (p instanceofStudent)31 System.out.println(p.getClass() 类的实例 是类Student的实例);32 if (p instanceofPerson1)33 System.out.println(p.getClass() 类的实例 是类Person的实例);34 if (p instanceofMan)35 System.out.println(p.getClass() 类的实例 是接口Man的实例);36 if (p instanceofObject)37 System.out.println(p.getClass() 类的实例 是类Object的实例);38 }39 }上面的程序展示各类之间的关系的继承树是上述程序中由上面继承树可知某个类(接口也可以看成一个特殊的类)的对象是不是其他类(或接口)的实例只需按箭头方向以此对象所在的类为起点到达此继承树分支(可能有多个分支)终点沿途经过的类(包括本类或接口)就都是该对象的实例。所以输出结果是但是要注意一点在判断某个类(接口也可以看成一个特殊的类)的对象是不是其他类(或接口)的实例一定要首先进行向上转型然后才可用instanceof关键字进行判断这是基本操作规范。如1 packageinstanceofTest;23 /**4 *authorzsh5 * company wlgzs6 * create 2019-03-21 20:027 * Describe8 */910 interfaceA{11 voidsay();12 }1314 class B implementsA{15 public voidsay()16 {17 System.out.println(B实现的say()方法);18 }19 }2021 class C implementsA{22 public voidsay()23 {24 System.out.println(C实现的say()方法);25 }26 }2728 public classMain2 {29 public static voidmain(String[] args) {30 A a new B(); //接口不能new31 System.out.println(a instanceof B); //true;发生了A a new B();32 System.out.println(a instanceof C); //false;没有发生A a new C();33 }34 }运行结果以上各类的之间关系的继承树如下在判断接口A的对象a 是不是类C的实例时没有先进行向上转型就进行instanceof关键字的使用了是肯定会返回false的。测试用例1 packageinstanceofTest;23 /**4 *authorzsh5 * company wlgzs6 * create 2019-03-21 20:077 * Describe instanceof 测试用例8 */9 interfaceA{1011 }12 class B implementsA{1314 }15 class C extendsB{1617 }18 public classMain3 {19 public static voidmain(String[] args) {20 A abnewB();21 A acnewC();22 B bcnewC();23 B bbnewB();24 C ccnewC();25 //对象实现一个接口用这个对象和这个接口进行instanceof判断都为true。26 System.out.println(ab instanceof A(ab instanceofA));27 System.out.println(ac instanceof A(ac instanceofA));28 System.out.println(bc instanceof A(bc instanceofA));29 System.out.println(bb instanceof A(bb instanceofA));30 System.out.println(cc instanceof A(cc instanceofA));31 //对象和父类进行instanceof判断都为true32 System.out.println(ab instanceof B(ab instanceofB));33 System.out.println(ac instanceof B(ac instanceofB));34 System.out.println(bc instanceof B(bc instanceofB));35 System.out.println(bb instanceof B(bb instanceofB));36 System.out.println(cc instanceof B(cc instanceofB));37 //对象和他的子类进行instanceof判断为false38 System.out.println(ab instanceof C(ab instanceofC));39 System.out.println(ac instanceof C(ac instanceofC));40 System.out.println(bc instanceof C(bc instanceofC));41 System.out.println(bb instanceof C(bb instanceofC));42 System.out.println(cc instanceof C(cc instanceofC));43 }44 }运行结果总结如果一个类的实例是这个类本身的实例那么它也是它的父类、它的父类的父类的实例也是由它实现的接口的实例且instanceof左边操作元显式声明的类型与右边操作元必须是同种类或右边是左边父类的继承关系此外//false;这是instanceof 特 有 的 规 则 若左操作数为null 结果就直接返回false 不再运算右操作数是什么类。boolean b5 null instanceof String;//编译不通过;A在此处视为基本数据类型charinstanceof操作符只能用作对象的判断boolean b4 A instanceof Character;
http://wiki.neutronadmin.com/news/224346/

相关文章:

  • 哪个网站做调查赚钱多wordpress 防爬
  • 现在怎么建设一个网站wordpress logy
  • 设计比较有特色的网站哈尔滨百度推广排名优化
  • 什么样的公司愿意做网站软文撰写公司
  • 网站空间国外那个好外贸网站建设 东莞
  • 厦门中小企业建网站补助黄页网络的推广
  • 郑州网站建设亻汉狮网络网络营销渠道管理
  • 企业网站制作深圳鞋行业的网站建设
  • 娄底高端网站建设wordpress 修改端口
  • 锡林浩特市长安网站 建设初步方案网页浏览器设置在哪里
  • 赣州网站制作公司百度有专做优化的没
  • 佛山网站建设全方位服务汽车之家网址
  • 贵港网站推广网络营销和网站推广的区别
  • 长安网站建设价格宝安专业网站设计公司
  • 网站宽屏背景网站运营托管协议
  • 网站建设对接模版网站划分栏目
  • 网站名 注册报告怎么写
  • 做网站卖广告位赚钱html5 jq做电脑网站
  • 网站开发公司有哪些椒江街道招聘建设网站
  • 酒店网站建设注意什么网页设计与制作工资
  • 网页特效网站建筑材料东莞网站建设
  • 成都网站制作汕头做网站用什么系统较好
  • 甘肃省住房城乡建设厅网站公司网络营销
  • 爱站网ip反查域名网站新闻源码
  • 实验室网站建设的调查报告建设网站有哪些
  • 网站建好以后每年都续费么用word怎么做网站
  • 首都医科大学网站建设凡科电脑版
  • 宁夏众擎达网站建设成都企业网站优化
  • 手表常用网站人工智能绘画
  • wordpress建站 评测苏州网站建设功能