• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            chenglong7997

            java instance()

             java 中的instanceof 運算符是用來在運行時指出對象是否是特定類的一個實例。instanceof通過返回一個布爾值來指出,這個對象是否是這個特定類或者是它的子類的一個實例。
             用法:
            result = object instanceof class
            參數:
            Result:布爾類型。
            Object:必選項。任意對象表達式。
            Class:必選項。任意已定義的對象類。
            說明:
            如果 object 是 class 的一個實例,則 instanceof 運算符返回 true。如果 object 不是指定類的一個實例,或者 object 是 null,則返回 false。

            例子如下:


            package com.instanceoftest;

             interface A{}
             class B implements A{
              
             }
             class C extends B {
              
             }
             
             class instanceoftest {
              public static void main(String[] args){
                 A a=null;
                 B b=null;
                 boolean res; 
                 
                 System.out.println("instanceoftest test case 1: ------------------");
                   res = a instanceof A; 
                   System.out.println("a instanceof A: " + res);
                   
                   res = b instanceof B;
                   System.out.println("b instanceof B: " + res);
                   
                 System.out.println("\ninstanceoftest test case 2: ------------------");   
                 a=new B();
                 b=new B();
                 
                 res = a instanceof A; 
                 System.out.println("a instanceof A: " + res);
                 
                 res = a instanceof B;
                 System.out.println("a instanceof B: " + res);

                 res = b instanceof A;
                 System.out.println("b instanceof A: " + res);
                 
                 res = b instanceof B;
                 System.out.println("b instanceof B: " + res);
                
                 System.out.println("\ninstanceoftest test case 3: ------------------");
                 B b2=(C)new C();
                 
                 res = b2 instanceof A;
                 System.out.println("b2 instanceof A: " + res);
                 
                 res = b2 instanceof B;
                 System.out.println("b2 instanceof B: " + res);
                 
                 res = b2 instanceof C;
                 System.out.println("b2 instanceof C: " + res);
              }
            }


            /*
            result:


            instanceoftest test case 1: ------------------
            a instanceof A: false
            b instanceof B: false

            instanceoftest test case 2: ------------------
            a instanceof A: true
            a instanceof B: true
            b instanceof A: true
            b instanceof B: true

            instanceoftest test case 3: ------------------
            b2 instanceof A: true
            b2 instanceof B: true
            b2 instanceof C: true

            posted on 2012-04-11 14:07 Snape 閱讀(410) 評論(0)  編輯 收藏 引用 所屬分類: Java

            導航

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            統計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            my

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            2021久久国自产拍精品| 97久久久久人妻精品专区| 人妻少妇精品久久| 东方aⅴ免费观看久久av| 精品久久久久久中文字幕| 久久久久久极精品久久久| 麻豆av久久av盛宴av| 精品久久久久久久无码| 久久夜色精品国产亚洲av| 东京热TOKYO综合久久精品| 久久久噜噜噜久久中文字幕色伊伊| 国产69精品久久久久观看软件| 久久精品国产99国产电影网| 麻豆精品久久久久久久99蜜桃| 91精品国产综合久久香蕉| 亚洲精品无码久久久久久| 久久精品国产一区二区三区不卡| 无码人妻久久一区二区三区蜜桃 | 久久国产精品免费一区| 久久久久久国产精品免费无码| 久久高潮一级毛片免费| 久久这里只有精品久久| 亚洲精品无码久久久久sm| 久久人人爽人人爽AV片| 色综合久久久久| 国内精品久久久久影院免费| 久久精品国产99久久久| 麻豆成人久久精品二区三区免费 | 青青草原综合久久大伊人导航| 欧美精品一区二区精品久久| 久久国产色AV免费观看| 久久天天躁狠狠躁夜夜躁2O2O| 亚洲午夜久久久久久噜噜噜| 国产aⅴ激情无码久久| 久久婷婷国产剧情内射白浆| 一本色综合久久| 亚洲精品无码久久久久去q| 久久天天婷婷五月俺也去| 久久精品久久久久观看99水蜜桃| 亚洲午夜精品久久久久久浪潮| 色综合久久夜色精品国产|