• <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 閱讀(408) 評論(0)  編輯 收藏 引用 所屬分類: Java

            導航

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            統計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            my

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久国产精品久久| 久久高潮一级毛片免费| 久久久久亚洲AV成人网| 亚洲国产另类久久久精品小说| 色欲久久久天天天综合网精品| 99久久99久久久精品齐齐| 伊人久久无码精品中文字幕| 久久久久久久97| 伊人久久大香线蕉综合影院首页| 亚洲成色999久久网站| 亚洲国产精品无码久久久秋霞2| 午夜天堂av天堂久久久| 久久亚洲电影| 1000部精品久久久久久久久| 一本久道久久综合狠狠躁AV| 久久精品这里热有精品| 久久精品国产亚洲麻豆| 亚洲精品乱码久久久久久蜜桃 | 久久久久99精品成人片| 久久婷婷国产剧情内射白浆| 久久精品国产色蜜蜜麻豆| 欧美va久久久噜噜噜久久| 狠狠色丁香久久婷婷综合蜜芽五月| 狠狠久久综合伊人不卡| 久久精品无码专区免费青青 | 久久久久国产亚洲AV麻豆| 久久综合给合久久狠狠狠97色69| 人人狠狠综合久久亚洲高清| 亚洲欧洲精品成人久久曰影片| 国产成人精品久久亚洲| 久久精品国产精品亚洲| 成人妇女免费播放久久久| 嫩草影院久久国产精品| 国产亚洲精品自在久久| 人妻精品久久无码专区精东影业| 久久噜噜久久久精品66| 久久亚洲中文字幕精品一区| 色欲综合久久躁天天躁| 99久久国产亚洲综合精品| 国产亚洲精品久久久久秋霞| 亚洲精品无码久久千人斩|