黑猴子的家:Java SE 練習(xí)題第四章

尾部都有答案

第四章練習(xí)題(封裝)

(1)下列有關(guān)類、對(duì)象和實(shí)例的敘述,正確的是哪一項(xiàng)?
A.類就是對(duì)象,對(duì)象就是類,實(shí)例是對(duì)象的另一個(gè)名稱,三者沒有差別
B.對(duì)象是類的抽象,類是對(duì)象的具體化,實(shí)例是對(duì)象的另一個(gè)名稱
C.類是對(duì)象的抽象,對(duì)象是類的具體化,實(shí)例是類的另一個(gè)名稱
D.類是對(duì)象的抽象,對(duì)象是類的具體化,實(shí)例是對(duì)象的另一個(gè)名稱
(2)下列類Account的構(gòu)造方法中,聲明正確的是?
A. Account (String name){)
B. Account (String  name)
C. Account (name)()
D. NewAccount (String name){)
(3)類Account中字段聲明正確的是哪項(xiàng)?
A.
    class  Account {
        name;
        Amount;
    )
B.
    class  Account {
        String name=l.0;
        Double amount="Mike";
    )
C.
    class  Account {
        String name;
        Double amount;
    )
D.
    class  Account {
        String   name= "Mike,,, double   amount=1000.0;
    )
(4)類Account中方法聲明正確的是哪一項(xiàng)?
A.
    class  Account {
        Deposit();
    )
B.
    class  Account {
        void deposit();
    } 
C.
    class  Account {
        void deposit(){)
    )
D.
    class Account {
        void  deposit{)
    )
(5)下列有關(guān)類聲明的代碼片段,哪一項(xiàng)是正確的?
A.
    package school;
    import  java. sql.*;
    Class Student {

    }
B.
    import java.sql.*;
    package school;
    Class  Student {

    )
C.
    package school;
    Class Student{

    }
    import  java. sql.*j
D.
    package school;
    import java. sql.*;
    private String name;
    Class Student {

    }
(6)有關(guān)new關(guān)鍵字的描述正確的是哪項(xiàng)?
A. 創(chuàng)建對(duì)象實(shí)例的時(shí)候可以不使用new關(guān)鍵字
B. new所創(chuàng)建的對(duì)象不占用內(nèi)存空間
C. new會(huì)調(diào)用類的構(gòu)造器來創(chuàng)建對(duì)象
D. new所創(chuàng)建的對(duì)象一定存在引用變量
(7)下列哪些是方法public int add (int a)的重載方法?(選三項(xiàng))
A.  public  int  add (long a);
B.  public  void  add (int a)j
C.  public void add (long a);
D.  public  int  add (float a); 
(8)我們定義一個(gè)Account類來描述銀行賬戶,銀行賬戶有賬戶名、金額等屬性特征,同時(shí)有存款、取款等行為特征,下述代碼適合描述的是哪項(xiàng)?
A.
    class  Account {
        String name; //賬戶
        String amount;  //金額
        Account (String name)(    )
        void deposit (double mount){  //存款
        )
        void withdraw (double mount){  //取款
        }
    )

B.
    class  Account {
        String name;//賬戶
        Doujole amount;  //金額
        Account (double amount){    )
        void deposit (double mount){  //存款
        )
        void withdraw (double mount){  //取款
        )
    )
C.
    class  Account {
        String name;//賬戶
        Double amount;  //金額
        Account (String name){    )
        void deposit (double mount){//存款
        )
        void withdraw (double mount){  //取款
        )
    )
D.
    class Account {
        String name;//賬戶
        Double amount;//金額
        Account (String name){    )
        void deposit(){//存款
        )
        void withdraw(){//取款
        )
    ) 
(9)現(xiàn)有
class Banana2  {
    static int X=2;
    public static void main (String  []  args)  {
        int X=2; 
        Banana2 b=new Banana2();
        go(x);
    }
    static  {x+=x;  )
    void go (int x)  {
        ++x;
        System. out.println (x);
    }
}

結(jié)果為

A. 7
B. 5
C. 3
D. 2
(10)現(xiàn)有
class TestFoo {
    int x;
    String y;
    int  getX()  {  return  x;  }
    String getY()  {return y;  }
    void setX (int  x)  {
        int Z=7:
        this.x=x;
    }
}

可以添加多少個(gè)修飾符來封裝此類?

A. 5
B. 4
C. 3
D. 2 
(11)定義枚舉如下
public  enum  Direction{
    EAST,SOUTH,WEST,NORTH
)

列正確使用該枚舉類型的語(yǔ)句是哪項(xiàng)?

A. Direction Direction=EAST;
B. Direction direction=Direction.WEST;
C. int a- Direction.NORTH;
D. Direction direction=2;
(12)定義類
package utils;
public class Rep {
    public static String twice (String s){return s+s ;)
}
//再定義另一個(gè)類Demo:
//insert code here
public class Demo{
    public static void main (String[]  args){
        System. out .println( twice( "Hello"));
    }
}

在第一行插入哪項(xiàng)代碼,可以使程序正常編譯和執(zhí)行?

A.import utils.*;
B. import utils.Rep.*;
C. import static utils.Rep.twice;
D. static import utils.Rep.twice;
(13)現(xiàn)有
public  class  TestDemo {
    private int X-2;
    static int y=3;
    public  void method() {
        final int i=100;
        int j  =10;
        Class Cinner {
            public void mymethod() {
            //Here
            }
        }
    }
} 

在Here處可以訪問的變量是哪些?(選三項(xiàng))

A. X
B. y
C. j
D. i
(14)現(xiàn)有如F包結(jié)構(gòu)
Com
    |一一X
    |    |一一Alpha.class
    |    |
    |    |一一y
    I         |一一Beta.class
    |
    |l-- Gamma.class
//和類
Class Test  {  Alpha a;  Beta b; Gamma c;  }

哪三個(gè)必須加入到類Test中,以使其通過編譯?(選三項(xiàng))

A. package y;
B. package com;
C. import com.x.y.*;
D. import com.x.*;
(15)現(xiàn)有2個(gè)文件
package x;
    public class X{
        public static void doX()  {System.out.print("doX");}
    }
//和
class Find{
    public static void main(String  []  args)  {
        //insert code here
    }
}

哪兩行分別插入到類Find的第3行將編譯并產(chǎn)生輸出“doX”?(選兩項(xiàng))

A. doX();
B. X.doX();
C. x.X.doX();
D. x.X myX = new x.X();myX.doX(); 

參考答案

1、D
2、A
3、C
4、C
5、A
6、C
7、ACD
8、C
9、C
10、D
11、B
12、C
13、ABD
14、BCD
15、CD 
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容