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

            導航

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            統計

            常用鏈接

            留言簿

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            my

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久国产精品无| 国内精品人妻无码久久久影院 | 日韩久久无码免费毛片软件| 久久综合给久久狠狠97色| 久久毛片一区二区| 亚洲精品午夜国产va久久| 亚洲另类欧美综合久久图片区| 久久精品国产亚洲精品| 久久性精品| 伊人久久大香线蕉精品不卡| 亚洲午夜精品久久久久久浪潮 | 伊人久久大香线蕉综合5g| 美女久久久久久| 亚洲精品综合久久| 亚洲午夜久久久久久久久久| 亚洲AV无码一区东京热久久| 亚洲AV无码1区2区久久| 性色欲网站人妻丰满中文久久不卡| 2021国内久久精品| 婷婷五月深深久久精品| 999久久久免费精品国产| 91久久婷婷国产综合精品青草 | 欧美色综合久久久久久| 要久久爱在线免费观看| 亚洲精品无码久久久久去q | 亚洲国产欧美国产综合久久| 久久精品午夜一区二区福利| 久久91精品久久91综合| 久久久国产一区二区三区| 麻豆精品久久久久久久99蜜桃| 亚洲狠狠婷婷综合久久久久| 久久综合狠狠色综合伊人| 久久午夜综合久久| 精品久久久久久久无码| 欧美与黑人午夜性猛交久久久| 99久久做夜夜爱天天做精品| 精品久久香蕉国产线看观看亚洲| 久久青青国产| 国产午夜精品久久久久免费视| 久久久久亚洲AV成人网| 亚洲中文精品久久久久久不卡|