亿搜题库-好用方便快捷的题库

免费慕课 Java语言程序设计I(武汉华夏理工学院)1457188161 最新慕课中国大学MOOC答案-亿搜题库

2078291 74 ℃ 0 条

前四章单元测验

1、单选题:
 有如下代码段:​public  static void booleanTest() {​        int a = 1, b =1;​        if (a == b || b<0)​            a++;​        if (a <= 2 &&(!(b<0)))​            b=b<<1;​        System.out.println(a + "," + b);​}​‎        则运行结果为:​‎​
选项:
A: 2,1
B: 2,2
C: 2,3
D: 1,2
答案: 【 2,2

2、单选题:
​如下赋值语句中,有语法错误的是?‎
选项:
A: float f1 = 1.2;
B: float f1 = 1.2f;
C: float f1 = 1;
D: float f1 = 0xAE;
答案: 【 float f1 = 1.2;

3、单选题:
有如下类定义:‎public class Rectangle {‎public int width = 3;‎public int height = 4;‎public int area() {‎        return width * height;‎}‎}‎则如下代码输出结果为:‎Rectangle rectangle;‎rectangle.height = 5;‎System.out.println(rectangle.area());‎
选项:
A: 15
B: 有编译错误,程序不能运行
C: 12
D: 0
答案: 【 有编译错误,程序不能运行

4、单选题:
执行如下代码片段后,i和n的值分别为:‏int i = 10;‏int n =( i++) % 5;‏
选项:
A: 11, 1
B: 11, 0
C: 10, 1
D: 10, 0
答案: 【 11, 0

5、单选题:
‏执行如下代码片段后,num的值为:​‏int num = 5;​‏num = (num % 2) == 0 ? num – 1 : num + 1;​
选项:
A: 1
B: 4
C: 5
D: 6
答案: 【 6

6、单选题:
‏有如下代码段:‌‏if (num >= 0)‌‏    if (num == 0)‌‏        System.out.println("first string");‌‏else ‌‏    System.out.println("second string");‌‏System.out.println("third string");‌‏若num为3,则输出结果为:‌
选项:
A: third string
B: second stringthird string
C: first stringthird string
D: first stringsecond stringthird string
答案: 【 second stringthird string

7、单选题:
​下列变量名称中,不属于有效Java变量命名的是?‍
选项:
A: $num
B: _int
C: 6nums
D: Jiayou
答案: 【 6nums

8、单选题:
‍对于Java1.7及之后版本,如下不能用于switch的类型是:‍
选项:
A: String
B: int
C: char
D: double
答案: 【 double

9、单选题:
‍如下对Java基本类型的描述,错误的是?​
选项:
A: char占1个字节
B: int 占4个字节
C: short 占2个字节
D: double占8个字节
答案: 【 char占1个字节

10、单选题:
​如下循环结构中,输出结果与其它三组不一致的一组是:​
选项:
A: for (int i = 0; i < 10; i++)System.out.println(i);
B: int i = 0;while (i < 10) System.out.println(i++);
C: int i = 0;for (;i < 10;) System.out.println(i++);
D: int i = 0;while (i++ < 10) System.out.println(i);
答案: 【 int i = 0;while (i++ < 10) System.out.println(i);

11、单选题:
​swap方法定义如下:‌​public static void swap(int num1, int num2) {‌​        int temp = num1;‌​        num1 = num2;‌​        num2 = temp;‌​ }‌​执行如下代码后,‌​       int num1 = 10;‌​       int num2 = 5;‌​       int num3 = 20;‌​       swap(num1, num2);‌​       swap(num2, num3);‌​ num1, num2, num3的值分别为:‌
选项:
A: 10, 5, 20
B: 5, 20, 10
C: 5, 10, 20
D: 20, 5, 10
答案: 【 10, 5, 20

12、单选题:
‎Number类定义如下:​‎public class Number {​‎    public int x;​‎ }​‎swap方法定义如下:​‎public static void swap(Number number1, Number number2)​‎    {​‎        int temp = number1.x;​‎        number1.x = number2.x;​‎        number2.x = temp;​‎    }​‎运行如下代码:​‎        Number number1 = new Number();​‎        Number number2 = new Number();​‎        Number number3 = new Number();​‎        number1.x = 1;​‎        number2.x = 2;​‎        number3.x = 3;​‎        swap(number1, number2);​‎        swap(number2, number3);​‎则number1.x, number2.x, number3.x的值分别为:​
选项:
A: 1, 2, 3
B: 2, 3, 1
C: 3, 2, 1
D: 1, 3, 2
答案: 【 2, 3, 1

13、单选题:
‍假设有boolean变量flag1,flag2,则如下表达式中哪个不能代表异或逻辑?(异或逻辑:如果a、b两个值不相同,则异或结果为true。如果a、b两个值相同,异或结果为false。)‏
选项:
A: flag1 != flag2
B: (flag1 == true && flag2 == false) || (flag1 == false && flag2 == true)
C: !flag1 == flag2
D: (flag1 == true && flag2 == true) || (flag1 == false && flag2 == false)
答案: 【 (flag1 == true && flag2 == true) || (flag1 == false && flag2 == false)

14、单选题:
‏如下关于Java类的说法,错误的是?​
选项:
A: 对象是类的实例化
B: 可以通过对象访问类变量
C: java文件中只能包含一个类的定义
D: 同一类的不同对象有着相同的类变量
答案: 【 java文件中只能包含一个类的定义

15、单选题:
‏如下赋值语句,有编译错误的是?‍
选项:
A: byte b = -127;
B: int i = (byte)512;
C: byte b = 129;
D: byte b = -0; 
答案: 【 byte b = 129;

16、单选题:
​下列关于main方法的描述中,错误的是?‎
选项:
A: main方法是Java程序的入口
B: main方法格式为public static void main(String[] args) {    //Your code here}
C: B选项中所描述格式中形参args不能更改,如果将args改为arguments则不能编译通过
D: main方法可以被重载
答案: 【 B选项中所描述格式中形参args不能更改,如果将args改为arguments则不能编译通过

17、单选题:
‎Java有“一次编译,到处运行”的说法,此种说法中编译的结果是:​
选项:
A: 机器码
B: 符号表
C: 字节码
D: 中间代码
答案: 【 字节码

18、单选题:
‌下列不属于Java基本数据类型的是?​
选项:
A: short
B: float
C: Double
D: int
答案: 【 Double

19、单选题:
​如下关于JDK和JRE的说法,错误的是?​
选项:
A: JDK全称Java Development Kit,意即Java开发工具包
B: JRE全程Java Runtime Environment,意即Java运行环境
C: JRE中包含了JDK
D: 若只需要运行编译好的Java程序,则只有JRE就可以
答案: 【 JRE中包含了JDK

20、单选题:
‌在Java中,下面对于构造函数的描述正确的是‌
选项:
A: 类必须显式定义构造函数
B: 构造函数的返回类型是void
C: 构造函数和类有相同的名称,并且不能带任何形参
D: 一个类可以定义多个构造函数
答案: 【 一个类可以定义多个构造函数

21、单选题:
‏Assume i and j are member variables with double type in class X. In the following codes, which one is NOT RIGHT constructor? ( )​
选项:
A: double X(double k ){ i=k; return i; }
B: X(double m, double n ){ i=m; j=n; }
C: X( ){i=6;j=8; }
D: X(double k ){ i=k; }
答案: 【 double X(double k ){ i=k; return i; }

22、单选题:
​Given:‏​class CardBoard {‏​  Short story = 5;‏​  CardBoard go(CardBoard cb) {‏​    cb = null;‏​    return cb;‏​  }‏​  public static void main(String[] args) {‏​    CardBoard c1 = new CardBoard();‏​    CardBoard c2 = new CardBoard();‏​    CardBoard c3 = c1.go(c2);‏​    c1 = null;‏​    // do Stuff‏​  } ‏​}‏​When // doStuff is reached, how many objects of CardBoard are null?‏​‏
选项:
A: 0
B: 1
C: 2
D: Compilation fails.
答案: 【 2

23、单选题:
‌Given the uncompleted code of a class:‎‌class Person {‎‌    String name, department;‎‌    int age;‎‌    public Person(String n){ name = n; }‎‌    public Person(String n, int a){ name = n; age = a; }‎‌    public Person(String n, String d, int a) {‎‌        // doing the same as two arguments version of constructor ‎‌        // including assignment name=n,age=a‎‌        department = d;‎‌   }‎‌}‎‌Which expression can be added at the "doing the same as…" part of the constructor? ‎
选项:
A: Person(n,a);
B: this(Person(n,a));
C: this(n,a);
D: this(name,age);
答案: 【 this(n,a);

24、单选题:
​Given the following class ‌​class MyNumber‌​{‌​   private int num = 5;‌​   public MyNumber(int num) { this.num = num; }‌​   public int getNum() { return num; }‌​   public void setNum(int num) { this.num = num; }‌​}‌​   What is output after the executation of following code? ‌​   MyNumber obj1 = new MyNumber();‌​   MyNumber obj2 = new MyNumber(10);‌​   obj2 = obj1;‌​   obj2.setNum(20);‌​   System.out.println(obj1.getNum() + “,” + obj2.getNum());‌​‌
选项:
A: 5, 20
B: 5, 10
C: 20,20
D: 编译错误
答案: 【 编译错误

25、单选题:
‏Given the following class:‎‏class Mixer {‎‏    Mixer() { }‎‏    Mixer(Mixer m) { m1 = m; }‎‏    Mixer m1;‎‏‎‏    public static void main(String[] args) {‎‏        Mixer m2 = new Mixer();‎‏        Mixer m3 = new Mixer(m2);  m3.go();‎‏        Mixer m4 = m3.m1;  m4.go();‎‏        Mixer m5 = m2.m1;  m5.go();‎‏    }‎‏    ‎‏    void go() { System.out.print("hi "); }‎‏}‎‏‎‏What is the result?‎
选项:
A: Compilation fails
B: hi hi hi
C: hi hi, followed by an exception
D: hi, followed by an exception
答案: 【 hi hi, followed by an exception

第五章继承、接口和抽象类

第五章单元测验

1、单选题:
现有‎‏    public class Parent{‎‏        public void change (int x){‎‏        }‎‏    }‎‏    public class Child extends Parent{‎‏    //覆盖父类change方法‎‏   }‎‏下列哪个声明是正确的覆盖了父类的change方法?‎‏‎
选项:
A: protected void change (int x){}
B: public void change(int x,  int y){}
C: public void change (int x){}
D: public void change (String s){}
答案: 【 public void change (int x){}

2、单选题:
‏ class Ca{     int num = 1;     Ca(int num){         this.num = num;         System.out.print(this.num);     }}class Cb extends Ca{‌‏    int num = 2;     Cb(int num) {         this.num = num;        System.out.print(num);‌‏     }     public static void main(String[] args) {         Ca a&n

发表评论 (已有0条评论)

快来评论,快来抢沙发吧~