1. 程式人生 > >刷題 day 05 Java

刷題 day 05 Java

1 Java中只有整型才能使用的運算子為©

A *
B /
C %
D +

2 下列程式碼中的錯誤是(D)

下列程式碼中的錯誤是()

(1)   public class Test
(2)   {
(3)       public static void main(String [] args)
(4)       {
(5)           int i;
(6)           i+=1;
(7)       }
(8)     }

A 非法的表示式
B 找不到符號i
C 類不應該為public
D 尚未初始化變數i

3 下列程式碼執行錯誤的是(B )

class B extends Object
{
    static
    {
        System.out.println("Load B");
    }
    public B()
    {
        System.out.println("Create B");
    }
}
class A extends B
{
    static
    {
        System.out.println("Load A");
    }
    public A()
    {
        System.out.println("Create A");
    }
}
 
public class Testclass
{
    public static void main(String[] args)
    {
        new A();
    }
}

不太會看

解析:執行順序:
父類靜態程式碼塊-》子類靜態程式碼塊-》父類構造程式碼塊-》父類建構函式-》子類構造程式碼塊-》子類建構函式

4 下面不屬於HttpServletRequest介面完成功能的是(C)

A 讀取cookie
B 讀取HTTP頭
C 設定響應的content型別(是response可以乾的事)
D 讀取路徑資訊
解析:HttpServletRequest類主要處理:

  1. 讀取和寫入HTTP頭標(Request.getHeader(neam))
  2. 取得和設定cookies (Request.getCookies( ))
  3. 取得路徑資訊 (Request.getContextPath( ))
  4. 標識HTTP會話

5.int i=5;int s=(i++)+(++i)+(i–)+(–i); s= ( ) s的值是(24)

解析:i++是先取值再加,++i是先加後取值。

回頭再看一遍 糊

6. 關於Spring的說法錯誤的是(D)

A spring是一個輕量級JAVA EE的框架集合
B spring是“依賴注入”模式的實現
C 使用Spring可以實現宣告事務
D Spring提供了AOP方式的日誌系統

7.package Wangyi;

class Base
{
    public void method()
    {
        System.out.println("Base");
    } 
}
class Son extends Base
{
    public void method()
    {
        System.out.println("Son");
    }
     
    public void methodB()
    {
        System.out.println("SonB");
    }
}
public class Test01
{
    public static void main(String[] args)
    {
        Base base = new Son();
        base.method();
        base.methodB();
    }
}

解析:Base base=new Son(); 是多型的表示形式。父類物件呼叫了子類建立了Son物件。
base呼叫的method()方法就是呼叫了子類重寫的method()方法。
而此時base還是屬於Base物件,base呼叫methodB()時Base物件裡沒有這個方法,所以編譯不通過。
要想呼叫的話需要先通過SON son=(SON)base;強制轉換,然後用son.methodB()呼叫就可以了。

同第三題 不太懂

8 根據下面的程式碼,String s =null;會丟擲NullPointerException異常的有(AC)

A if( (s!=null) & (s.length()>0) )
B if( (s!=null) && (s.length()>0) )
C if( (s==null) | (s.length()0) )
D if( (s
null) || (s.length()==0) )
解析:String s=null;沒有給s開闢任何空間,當執行length()方法時候,因為沒有具體指向的記憶體空間,所以報出NullPointerException沒有指向的錯誤。A &是與,位運算,兩個都得執行,執行到s.length()自然就報錯了。B S!=null 結果為false 整體就為false ,&& 後面就不會執行。下面的同理。

9 Model-View-Controller(MVC) is an architectural pattern that frequently used in web applications. Which of the following statement(s) is(are) correct?

A Models often represent data and the business logics needed to manipulate the data in the application
B A view is a (visual) representation of its model. It renders the model into a form suitable for interaction, typically a user interface element
C A controller is the link between a user and the system. It accepts input from the user and instructs the model and a view to perform actions based on that input
D The common practice of MVC in weapplications is, the model receives GET or POST input from user and decides what to do with it, handing over to controller and which hand control to views(HTML-generating components)
E None of the above
解析:翻譯
MVC是一種在web應用中常用的架構,下列說法正確的是()

A. 模型通常代表應用程式中的資料以及用於操縱資料的業務邏輯;

B. 檢視是其對應的模型的視覺化呈現,檢視 將模型渲染成適合於互動的形式(通常為使用者介面元素);

C. 控制器是使用者與系統之間的紐帶,它接受使用者輸入,並指示模型和檢視基於使用者輸入執行操作(處理資料、展示資料);

D. MVC模式在web應用中的常見實踐是:模型接受來自於使用者的GET或POST請求資料並決定如何處理,模型將使用者資料轉交給控制器,控制器將控制權轉交給檢視(檢視由HTML生成);

E. 以上全不是。