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

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲∧v久久久无码精品| 99久久综合狠狠综合久久| 久久人人爽人人人人片av| 午夜不卡久久精品无码免费| 99精品国产在热久久| 久久国产精品免费一区| 亚洲美日韩Av中文字幕无码久久久妻妇 | 蜜臀久久99精品久久久久久小说 | 精品久久综合1区2区3区激情| 久久www免费人成看国产片| 一本久久知道综合久久| 亚洲国产精品久久久久| 久久久久久久久久久精品尤物 | 精品人妻伦九区久久AAA片69| 伊人久久无码中文字幕| 狠狠久久综合| 久久99热精品| 男女久久久国产一区二区三区| 久久天天日天天操综合伊人av| 国产精品美女久久久| 精品国产乱码久久久久久人妻| 久久久久久国产精品无码下载| 91精品国产综合久久久久久| 久久久久亚洲AV成人网人人网站 | 国内精品久久久久影院优| 亚洲国产视频久久| 免费一级欧美大片久久网| 91精品久久久久久无码| 国产精品青草久久久久婷婷 | 99久久精品毛片免费播放| 久久久久高潮综合影院| 久久精品桃花综合| 国产精品成人久久久| 久久精品三级视频| 久久久久九国产精品| 久久夜色撩人精品国产| 久久久久无码国产精品不卡| 色综合久久88色综合天天 | 色婷婷狠狠久久综合五月| 久久夜色精品国产| 狠狠色婷婷久久一区二区|