日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

全网最细之instanceof和类型转换

發布時間:2024/9/27 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 全网最细之instanceof和类型转换 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
package com.wuming.oop4.demo08;public class Application {public static void main(String[] args) {//類型之間轉換:父 子//高 低Person person1 = new Student();//student將這個對象轉換為student類型,我們就可以使用student類型的方法了!Student student = (Student) person1;student.go();//go((Student) person1).go();//go//從右往左看Person person=student;//子類轉父類Student student1= (Student) person1;// 父轉子,強制} } /* 1.父類引用指向子類對象 2.子類轉換為父類,向上轉型 3.父轉子,強制 4.方便方法的調用,減少重復的代碼 */ package com.wuming.oop4.demo08;public class Person {} package com.wuming.oop4.demo08;public class Student extends Person {public void go() {System.out.println("go");}//Application.java里面的拿過來的 // //Object>String // //Object>Person>Teacher // //Object>Person>Student 三行中同級間(列對應)instance of指向會報錯 // Object object = new Student(); // //System.out.println(x instanceof y);//能不能編譯通過,就看x和y有沒有父子關系 // System.out.println(object instanceof Student);//true // System.out.println(object instanceof Person);//true // System.out.println(object instanceof Object);//true // System.out.println(object instanceof Teacher);//false // System.out.println(object instanceof String);//false // System.out.println("==================="); // Person person = new Student(); // System.out.println(person instanceof Student);//true // System.out.println(person instanceof Person);//true // System.out.println(person instanceof Object);//true // // System.out.println(person instanceof Teacher); // // System.out.println(person instanceof String);編譯報錯 // System.out.println("==================="); // Student student = new Student(); // System.out.println(student instanceof Student);//true // System.out.println(student instanceof Person);//true // System.out.println(student instanceof Object);//true // // System.out.println(student instanceof Teacher); // // System.out.println(student instanceof String); }

go
go
?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的全网最细之instanceof和类型转换的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。