學了一陣子基礎,做做題目. 記錄--5.31

          Posted on 2007-05-31 14:59 yiraka 閱讀(258) 評論(0)  編輯  收藏 所屬分類: scjp

          1.簡單的一題,錯了.
          自動轉型
          class Test {
           void test(int i){
            System.out.println("i");
           }
           void test(String s){
            System.out.println("s");
           }

           public static void main(String[] args){
            Test t=new Test();
            char ch='y';

            t.test(y);
           }
          }

          運行結果為"i",在編譯自動把字符型轉換為整型!!

          2.Reader/Writer只處理Unicode字符的輸入輸出。float和double可以通過stream進行I/O

          3.線程
          public class Z { 
          public static void main(String[] args) { 
            new Z(); 
            } 
             
            Z() { 
             Z alias1 = this; 
             Z alias2 = this; 
             synchronized(alias1) { 
            try { 
             alias2.wait(); 
             System.out.println(“DONE WAITING”); 
             } 
             catch (InterruptedException e) { 
             System.out.println(“INTERR UPTED”); 
             } 
             catch (Exception e) { 
            System.out.println(“OTHER EXCEPTION”); 
            } 
            finally { 
             System.out.println (“FINALLY”); 

            } 
            } 
             System.out.println(“ALL DONE”); 
            } 
            } 
          alias1,alias2引用同一個對象,當執行wait()方法時,線程放棄對象鎖,因無notifyAll()和notify()方法,{這個方法是把對象的等待池中的線程放入對象的鎖池,以便獲得對象鎖},所以對象一直處于等待的狀態什么也不打印)

          13
          class Person {
          private int a;
          public int change(int m){ return m; }
          }

          public class Teacher extends Person {
          public int b;
          public static void main(String arg[]){
          Person p = new Person();
          Teacher t = new Teacher();
          int i;
          // point x
          }
          }

          A. i = m;
          B. i = b;
          C. i = p.a;
          D. i = p.change(30);
          E. i = t.b. 
          A.m局域變量,等于未定義.B.在靜態方法中不能使用非靜態成員變量,可通過類的實例的引用來調用.
          如i=t.b
          C.a是私有成員.



          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          posts - 8, comments - 0, trackbacks - 0, articles - -1

          Copyright © yiraka

          主站蜘蛛池模板: 长治市| 岳阳市| 云龙县| 洮南市| 西盟| 略阳县| 松原市| 南川市| 金门县| 周口市| 瑞丽市| 禄丰县| 洛隆县| 南江县| 泾源县| 旬阳县| 临桂县| 岑溪市| 宁德市| 廊坊市| 静海县| 深水埗区| 宽城| 泾川县| 无为县| 托里县| 浪卡子县| 青州市| 久治县| 芜湖县| 玛曲县| 建昌县| 云南省| 锡林郭勒盟| 灯塔市| 封开县| 宜川县| 天气| 健康| 鄂尔多斯市| 安化县|