隨筆-61  評論-13  文章-19  trackbacks-0

          2.下面代碼的輸出是什么?一共在內(nèi)存中生成了幾個String對象?為什么?
          String s1 = “aaa”;
          String s2 = “aaa”;
          String s3 = new String(“aaa”);
          String s4 = new String(“AAA”);
          System.out.println(s1 == s2);
          System.out.println(s1 == s3);
          System.out.println(s1.equals(s3));

          3.下列程序在1處是否會有異常,如果沒有,輸出是什么?是否會運行到2處,如果會,輸出是什么?為什么會有這樣的結(jié)果?
          public class TestClass {
          public void test1() {
          List list = new ArrayList();
          test2(list);
          System.out.println(list.size()); // 1處
          test3(list);
          System.out.println(list.size()); // 2處
          }

          public void test2(List list) {
          list = null;
          }

          public void test3(List list) {
          list.add(“aaaa”);
          }
          }

          4.請選出下面哪些描述是正確的。
          public class ClassA {
          public synchronized void a(){
          }
          public synchronized void b(){
          }
          }
          2 instances of ClassA had been instantiated obj1 and obj2.
          Which statements about thread are true?
          1)One thread is calling obj1.a(), another thread can call obj1.b().? .
          2)One thread is calling obj1.a(), another thread cannot call obj1.b().?
          3)One thread is calling obj1.a(), another thread can call obj2.b().? .
          4)One thread is calling obj1.a(), another thread cannot call obj2.b().?


          5.下面的程序輸出是什么?為什么?
          public class Parent {
          public void test(ArrayList list) {
          System.out.println("invoke parent's test method");
          }

          public static void main(String[] args) {
          Child a = new Child();
          ArrayList list = new ArrayList();
          a.test(list);
          }
          }

          class Child extends Parent {
          public void test(List list) {
          System.out.println("invoke child's test method");
          }
          }

          6.下面的程序輸出是什么?為什么?
          public class Parent {
          public void test(List list) {
          System.out.println("invoke parent's test method");
          }

          public static void main(String[] args) {
          Child a = new Child();
          ArrayList list = new ArrayList();
          a.test(list);
          }
          }

          class Child extends Parent {
          public void test(List list) {
          System.out.println("invoke child's test method");
          }
          }

          7.仔細分析下面的程序,寫出程序的輸出結(jié)果。
          public class Parent {
          {
          System.out.println("parent instance block");
          }

          public void test() {
          System.out.println("parent test method");
          }

          static {
          System.out.println("parent static block");
          }

          public Parent() {
          System.out.println("parent constructor");
          test();
          }

          public static void main(String[] args) {
          new Child();
          }
          }

          class Child extends Parent {

          private static int staticValue = 20;
          private int instanceValue = 20;

          {
          System.out.println("child instance block");
          }

          public void test() {
          System.out.println("child test method");
          System.out.println("static value is: " + staticValue);
          System.out.println("instance value is: " + instanceValue);
          }

          static {
          System.out.println("child static block");
          }

          public Child() {
          System.out.println("child constructor");
          }
          }

          8.下面程序的輸出是什么?
          public class TestException {
          public void test1() {
          int result = test2();
          System.out.println(result);
          }

          public int test2() {
          try{
          String s = null;
          s.substring(0, 1);
          return 1;
          } catch(Exception e) {
          return 2;
          } finally {
          return 3;
          }
          }

          public static void main(String[] args) {
          (new TestException()).test1();
          }
          }

          9.請寫出數(shù)據(jù)庫查詢操作的偽代碼,程序不需要通過編譯,只要思路正確,關(guān)鍵步驟不丟失就可以了。注意異常的捕獲,IO流的關(guān)閉。可能用到的類或接口有(Connection,DriverManager, Statement, PreparedStatement, ResultSet, SQLException)。

          posted on 2006-03-19 23:12 xnabx 閱讀(146) 評論(0)  編輯  收藏

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 临城县| 托克逊县| 攀枝花市| 秭归县| 晋江市| 阳山县| 巧家县| 南投县| 威宁| 瑞丽市| 深泽县| 武定县| 唐河县| 江阴市| 黔西| 三门峡市| 无为县| 廊坊市| 莱西市| 凤城市| 开封县| 青铜峡市| 定南县| 沿河| 棋牌| 平乐县| 阿拉尔市| 孝义市| 巴林右旗| 和平县| 海口市| 曲靖市| 普定县| 太仆寺旗| 城市| 宁强县| 揭东县| 博爱县| 遂川县| 新绛县| 正安县|