• <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

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            日产精品99久久久久久| 国产精品久久久久久久| 久久伊人中文无码| 亚洲乱码日产精品a级毛片久久 | 91精品国产综合久久久久久| 久久国产亚洲精品麻豆| 四虎亚洲国产成人久久精品| 久久国产色av免费看| 国产精品激情综合久久| 亚洲午夜久久久影院| 99久久婷婷国产综合精品草原| 99国产精品久久| 欧美日韩精品久久久久| 99久久免费国产精品热| 18禁黄久久久AAA片| 久久国产精品99精品国产987| 日韩va亚洲va欧美va久久| 午夜精品久久久久久久久| 久久精品国产亚洲7777| 久久AV高清无码| 一本久久a久久精品亚洲| 国产精品美女久久久久av爽| 亚洲精品乱码久久久久久| 久久91精品综合国产首页| 国产午夜福利精品久久2021 | 成人午夜精品无码区久久| 青青青国产成人久久111网站| 中文精品久久久久人妻不卡| 亚洲人成无码网站久久99热国产| 91视频国产91久久久| 久久久久人妻精品一区二区三区 | 无码国内精品久久人妻麻豆按摩| 久久精品国产只有精品2020| 久久精品亚洲中文字幕无码麻豆| 久久精品桃花综合| 伊色综合久久之综合久久| 久久久久国产视频电影| 精品久久久久久国产牛牛app| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久婷婷五月综合国产尤物app| 久久久久久久综合综合狠狠|