大学MOOC JAVA语言程序设计(厦门理工学院)1450458198 最新慕课完整章节测试答案
第一章 Java概述
文章目录
第一章单元测试
1、单选题:
Java由哪个公司推出?
选项:
A: SUN Microsystems
B: Microsoft
C: Apple
D: Oracle
答案: 【 SUN Microsystems】
2、单选题:
以下哪种开发语言不属于面向对象编程语言?
选项:
A: Java
B: C++
C: C
D: Python
答案: 【 C】
3、单选题:
什么定义了Java开发语言的语法和语义
选项:
A: Java API
B: Java语言规范(Java language specification)
C: Java JDK
D: Java IDE
答案: 【 Java语言规范(Java language specification)】
4、单选题:
什么包含了为开发Java程序而预定义的类和接口?
选项:
A: Java language specification
B: Java API
C: Java JDK
D: Java IDE
答案: 【 Java API】
5、单选题:
什么可以用于编译、运行和测试Java程序
选项:
A: Java language specification
B: Java API
C: Java JDK
D: Java IDE
答案: 【 Java JDK】
6、单选题:
什么只能用于运行Java程序?
选项:
A: Java JDK
B: Java API
C: JRE
D: Java IDE
答案: 【 JRE】
7、单选题:
以下哪个main方法是正确的?
选项:
A: public static void main(string[] args)
B: public static void Main(String[] args)
C: public static void main(String[] args)
D: public static main(String[] args)
E: public void main(String[] args)
答案: 【 public static void main(String[] args)】
8、单选题:
以下那句话是正确的?
选项:
A: 程序中的每一行都必须以分号结束
B: 程序中的每个语句都必须以分号结束
C: 每个方法必须以分号结束
D: 每个类必须以分号结束
答案: 【 程序中的每个语句都必须以分号结束】
9、单选题:
以下那行代码能正确的显示Welcome to Java
选项:
A: System.out.println('Welcome to Java');
B: System.out.println("Welcome to Java");
C: System.println('Welcome to Java');
D: System.out.println('Welcome to Java");
答案: 【 System.out.println("Welcome to Java");】
10、单选题:
以下哪个命令用于编译Test.java 类
选项:
A: java Test
B: java Test.java
C: javac Test.java
D: javac Test
答案: 【 javac Test.java】
11、单选题:
以下哪个命令可以运行ByteCode.class?
选项:
A: java ByteCode
B: java ByteCode.class
C: javac ByteCode.java
D: javac ByteCode
答案: 【 java ByteCode】
12、单选题:
Java编译是将java 源代码编译为?
选项:
A: Java 字节码
B: 机器代码
C: 汇编代码
D: 高级语言代码
答案: 【 Java 字节码】
13、单选题:
以下哪个软件用于执行Java 字节码
选项:
A: Java virtual machine (JVM)
B: Java compiler
C: Java debugger
D: Java API
答案: 【 Java virtual machine (JVM)】
14、单选题:
假设定义如下的Java类public class Test {}这个类的文件名需要命名为什么才能进行编译?
选项:
A: Test.class
B: Test.doc
C: Test.txt
D: Test.java
答案: 【 Test.java】
15、单选题:
Java源代码的扩展名是什么?
选项:
A: .java
B: .obj
C: .class
D: .exe
答案: 【 .java】
16、单选题:
Java中每条语句需要以什么结尾?
选项:
A: 冒号 ;
B: 逗号,
C: 句号.
D: 不用符号结尾
答案: 【 冒号 ;】
17、单选题:
Java 块(block)需要用什么括起来?
选项:
A: 花括号{}
B: 圆括号()
C: 方括号[]
D: 引号“”
答案: 【 花括号{}】
第三章 Java类基础知识
Java类基础测试
1、单选题:
下列代码输出什么? double area = 3.5; System.out.print("area"); System.out.print(area);
选项:
A: 3.53.5
B: 3.5area
C: area3.5
D: 3.5area
答案: 【 area3.5】
2、单选题:
要将数字1赋给变量x,下列哪个写法是正确的?
选项:
A: 1 = x;
B: x = 1;
C: x := 1;
D: x == 1;
答案: 【 x = 1;】
3、单选题:
java 语句中 45 / 4的结果是什么
选项:
A: 10
B: 11
C: 11.25
D: 12
答案: 【 11】
4、单选题:
下列哪一赋值语句是不正确的?
选项:
A: int x = 9;
B: long x = 9;
C: float x = 1.0;
D: double x = 1.0;
答案: 【 float x = 1.0;】
5、单选题:
语句 (double)5/2 的值是多少?
选项:
A: 2
B: 2.5
C: 3
D: 2.0
答案: 【 2.5】
6、单选题:
下列代码的输出是什么? int x = 0;if (x < 4) { x = x + 1;}System.out.println("x is " + x);
选项:
A: x is 0
B: x is 1
C: x is 2
D: x is 3
答案: 【 x is 1】
7、单选题:
假设income 的值是4001,下面代码的输出是什么?if (income > 3000) { System.out.println("Income is greater than 3000");}else if (income > 4000) { System.out.println("Income is greater than 4000");}
选项:
A: 没有输出
B: Income is greater than 3000
C: Income is greater than 4000
D: Income is greater than 3000 Income is greater than 4000
答案: 【 Income is greater than 3000 】
8、单选题:
假设x = 1 y = -1 z = 1。下列语句的输出是什么?if (x > 0) if (y > 0) System.out.println("x > 0 and y > 0");else if (z > 0) System.out.println("x < 0 and z > 0");
选项:
A: x > 0 and y > 0;
B: x < 0 and z > 0;
C: x < 0 and z < 0;
D: 没有输出
答案: 【 x < 0 and z > 0;】
9、单选题:
以下代码会有什么问题?boolean even = false;if (even = true) { System.out.println("It is even");}
选项:
A: 编译错误
B: 运行错误
C: 什么都不输出
D: 输出 it is even
答案: 【 输出 it is even】
10、单选题:
下面的代码会输出多少次“Welcome to Java”int count = 0;while (count < 10) { System.out.println("Welcome to Java"); count++;}
选项:
A: 8
B: 9
C: 10
D: 11
答案: 【 10】
11、单选题:
下列代码的输出是什么?int x = 0;while (x < 4) { x = x + 1;}System.out.println("x is " + x);
选项:
A: x is 0
B: x is 1
C: x is 3
D: x is 4
答案: 【 x is 4】
12、单选题:
执行下面的switch语句后,y的值将是多少?int x = 3; int y = 4;switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1;}
选项:
A: 1
B: 2
C: 3
D: 0
答案: 【 2】
13、单选题:
下面的循环会输出什么?for (int i = 1; i <= 10; i++) { System.out.print(i + " "); i++;}
选项:
A: 1 2 3 4 5 6 7 8 9
B: 1 2 3 4 5 6 7 8 9 10
C: 1 3 5 7 9
D: 2 4 6 8 10
答案: 【 1 3 5 7 9】
14、单选题:
下面语句输出了多少次?for (int i = 0; i < 10; i++) for (int j = 0; j < i; j++) System.out.println(i * j)
选项:
A: 100
B: 20
C: 10
D: 45
答案: 【 45】
15、单选题:
执行下面的for循环语句后,y值会是多少?int y = 0;for (int i = 0; i < 10; ++i) { y = y+1; }
选项:
A: 9
B: 10
C: 11
D: 12
答案: 【 10】
16、多选题:
下列声明变量的正确方法有哪些?
选项:
A: int length; int width;
B: int length, width;
C: int length; width;
D: int length, int width;
答案: 【 int length; int width;;
int length, width;】
17、多选题:
下列哪几个赋值语句是非法的?
选项:
A: float f = -34;
B: int t = 4.5;
C: short s = 10;
D: int t = (int)false;
答案: 【 int t = 4.5;;
int t = (int)false;】
第四章 面向对象和类 (续)
前四章 单元测验
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: void
B: int
C: double
D: float
答案: 【 void】
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、单选题:
每次调用一个方法时,系统将参数和局部变量存储在一个什么样的内存区域中,该区域以后进先出的方式存储元素。
选项:
A: 堆
B: 存储区域
C: 栈
D: 数组
答案: 【 栈】
5、单选题:
请用用以下代码填充空白_____public class Test { public static void main(String[] args) { System.out.print("The grade is "); printGrade(78.5); System.out.print("The grade is "); printGrade(59.5); } public static __________ printGrade(double score) { if (score >= 90.0) { System.out.println('A'); } else if (score >= 80.0) { System.out.println('B'); } else if (score >= 70.0) { System.out.println('C'); } else if (score >= 60.0) { System.out.println('D'); } else { System.out.println('F'); } }}
选项:
A: int
B: double
C: void
D: char
答案: 【 void】
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、单选题:
考虑以下不完整的代码:public class Test { public static void main(String[] args) { System.out.println(f(5)); } public static int f(int number) { // Missing body }}缺少的方法主体应该是。
选项:
A: return "number";
B: System.out.println(number);
C: System.out.println("number");
D: return number;
答案: 【 return number;】
8、单选题:
分析下列代码public class Test { public static void main(String[] args) { System.out.println(xMethod(5, 500L)); } public static int xMethod(int n, long l) { System.out.println("int, long"); return n; } public static long xMethod(long n, long l) { System.out.println("long, long"); return n; }}
选项:
A: 程序显示int,long5
B: 程序显示long,long5
C: 程序只显示5
D: 程序无法编译,因为编译器无法区分要调用哪个xmethod方法。
答案: 【 程序显示int,long5】
9、单选题:
分析以下代码class Test { public static void main(String[] args) { System.out.println(xmethod(5)); } public static int xmethod(int n, long t) { System.out.println("int"); return n; } public static long xmethod(long n) { System.out.println("long"); return n; }}
选项:
A: 程序显示 int5
B: 程序显示 long5
C: 程序仅仅显示 5
D: 程序无法编译,因为编译器无法区分要调用哪个xmethod。
答案: 【 程序显示 long5】
10、单选题:
分析以下代码:public class Test { public static void main(String[] args) { System.out.println(max(1, 2)); } public static double max(int num1, double num2) { System.out.println("max(int, double) is invoked"); if (num1 > num2) return num1; else return num2; } public static double max(double num1, int num2) { System.out.println("max(double, int) is invoked"); if (num1 > num2) return num1; else return num2; }}
选项:
A: 程序无法编译,因为您不能在非void方法中调用print语句
B: 程序无法编译,因为编译器无法确定应该调用哪个max方法。
C: 程序调用“max(int, double)”运行并打印2。
D: 程序调用“max(double, int)”运行并打印2。
答案: 【 程序无法编译,因为编译器无法确定应该调用哪个max方法。】
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、单选题:
分析以下代码public class Test { public static void main(String[] args) { System.out.println(m(2)); } public static int m(int num) { return num; } public static void m(int num) { System.out.println(num); }}
选项:
A: 程序有编译错误,因为这两个方法m有相同的方法签名。
B: 该程序有编译错误,因为定义了第二个m方法,但是没有在主方法中调用。
C: 程序运行并打印1次。
D: 程序运行并打印2次。
答案: 【 程序有编译错误,因为这两个方法m有相同的方法签名。】
14、单选题:
如下关于Java类的说法,错误的是?
选项:
A: 对象是类的实例化
B: 可以通过对象访问类变量
C: java文件中只能包含一个类的定义
D: 同一类的不同对象有着相同的类变量
答案: 【 java文件中只能包含一个类的定义】
15、单选题:
下面的代码块执行后的k是多少{ int k = 2; nPrint("A message", k);}System.out.println(k);
选项:
A: 0
B: 1
C: 2
D: k在块外没有定义。因此,程序有一个编译错误
答案: 【 k在块外没有定义。因此,程序有一个编译错误】
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、单选题:
什么可以代表在现实世界中一个实体,可以被明确地确定
选项:
A: 类
B: 对象
C: 方法
D: 属性(成员变量)
答案: 【 对象】
18、单选题:
什么用来调用创建对象
选项:
A: 构造器
B: main方法
C: 具有返回类型的方法
D: 具有void返回类型的方法
答案: 【 构造器】
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、单选题:
分析下列代码public class Test { public static void main(String[] args) { A a = new A(); a.print(); }} class A { String s; A(String s) { this.s = s; } void print() { System.out.println(s); }}
选项:
A: 这个程序有一个编译错误,因为a类不是一个public类。
B: 这个程序有一个编译错误,因为a类没有默认的构造函数。
C: 该程序编译和运行良好,什么也不打印。
D: 该程序编译和运行良好,打印s。
答案: 【 这个程序有一个编译错误,因为a类没有默认的构造函数。】
22、单选题:
分析下面代码class TempClass { int i; public void TempClass(int j) { int i = j; }} public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); }}
选项:
A: 这个程序有一个编译错误,因为TempClass没有默认的构造函数。
B: 这个程序有一个编译错误,因为TempClass没有一个带有int参数的构造函数。
C: 这个程序编译得很好,但是它不能运行,因为C类不是public 类的。
D: 这个程序编译但是不能运行
答案: 【 这个程序有一个编译错误,因为TempClass没有一个带有int参数的构造函数。】
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、单选题:
假设声明初始化Circle x = new Circle(),下面那句话表达是最准确的。
选项:
A: x包含一个int值。
B: x包含一个Circle类型的对象。
C: x包含对Circle对象的引用。
D: 可以将一个int值赋给x。
答案: 【 x包含对Circle对象的引用。】
25、单选题:
布尔类型、数值类型、对象类型的数据字段的默认值分别为。
选项:
A: true, 1, Null
B: false, 0, null
C: true, 0, null
D: true, 1, null
答案: 【 false, 0, null】
第五章 继承、接口和抽象类
第五章 第一次单元测试
1、单选题:
面向对象编程允许您从现有类派生新类。这就是所谓的
选项:
A: 封装
B: 继承
C: 实现
D: 抽象
答案: 【 继承】
2、单选题:
假设您创建了一个类Square是GeometricObject的子类。分析以下代码:class Square extends GeometricObject { double length; Square(double length) { GeometricObject(length); }}
选项:
A: 程序编译正常,但是您不能创建Square的实例,因为构造函数没有指定Square的长度。
B: 该程序有一个编译错误,因为您试图非法调用GeometricObject类的构造函数。
C: 该程序编译正常,但由于非法调用Square类的构造函数而出现运行时错误。
D: 该程序有一个编译错误,因为GeometricObject类没有 GeometricObject(length)构造函数。
答案: 【 该程序有一个编译错误,因为您试图非法调用GeometricObject类的构造函数。】
3、单选题:
运行C类的输出是什么?class A { public A() { System.out.println( "The default constructor of A is invoked"); }} class B extends A { public B() { System.out.println( "The default constructor of B is invoked"); }} public class C { public static void main(String[] args) { B b = new B(); }}
选项:
A: 什么都不输出
B: 输出: "The default constructor of B is invoked"
C: 输出:"The default constructor of A is invoked" "The default constructor of B is invoked"
D: 输出:"The default constructor of B is invoked" "The default constructor of A is invoked"
答案: 【 输出:"The default constructor of A is invoked" "The default constructor of B is invoked"】
4、单选题:
关于super关键字,下列哪个陈述是不正确的?
选项:
A: 可以使用super调用父类构造函数。
B: 您可以使用super来调用父类方法
C: 你可以用super.super在父类的父类中调用一个方法。
D: 不能调用父类的父类中的方法
答案: 【 你可以用super.super在父类的父类中调用一个方法。】
5、单选题:
下列哪个类定义定义了一个正确的抽象类?
选项:
A: class A { abstract void unfinished() { } }
B: class A { abstract void unfinished(); }
C: abstract class A { abstract void unfinished(); }
D: public class abstract A { abstract void unfinished(); }
答案: 【 abstract class A { abstract void unfinished(); }】
6、单选题:
下列哪个选项在Java抽象类中声明了抽象方法?
选项:
A: public abstract method();
B: public abstract void method();
C: public void abstract method();
D: public abstract void method() {}
答案: 【 public abstract void method();】
7、单选题:
下列关于抽象方法的陈述哪一个是错误的?
选项:
A: 抽象类可以使用抽象类的构造函数创建实例
B: 抽象类可以继承
C: 非抽象父类的子类可以是抽象的。
D: 子类可以覆盖父类中的具体方法来声明它是抽象的。
答案: 【 抽象类可以使用抽象类的构造函数创建实例】
8、单选题:
下列关于抽象方法的陈述哪一个是错误的?
选项:
A: 抽象类有构造函数
B: 包含抽象方法的类必须是抽象的。
C: 可以声明一个不包含抽象方法的抽象类。
D: 属性可以声明为抽象。
答案: 【 属性可以声明为抽象。】
9、单选题:
运行Test类的输出是什么?public class Test { public static void main(String[] args) { new Circle9(); }} public abstract class GeometricObject { protected GeometricObject() { System.out.print("A"); } protected GeometricObject(String color, boolean filled) { System.out.print("B"); }} public class Circle9 extends GeometricObject { /** No-arg constructor */ public Circle9() { this(1.0); System.out.print("C"); } /** Construct circle with a specified radius */ public Circle9(double radius) { this(radius, "white", false); System.out.print("D"); } /** Construct a circle with specified radius, filled, and color */ public Circle9(double radius, String color, boolean filled) { super(color, filled); System.out.print("E"); }}
选项:
A: ABCD
B: BEDC
C: AEDC
D: CBAE
答案: 【 BEDC】
10、单选题:
下列哪个接口是正确的?
选项:
A: interface A { void print() { }; }
B: abstract interface A { print(); }
C: abstract interface A { abstract void print() { };}
D: interface A { void print();}
答案: 【 interface A { void print();}】
11、单选题:
以下哪个不是引用类型?
选项:
A: 类
B: 接口
C: 数组
D: 基本类型
答案: 【 基本类型】
12、单选题:
以下代码行中运行Test类的输出是?interface A {} class C { } class B extends D implements A {} public class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); if (b instanceof C) System.out.println("b is an instance of C"); }} class D extends C { }
选项:
A: 什么都不输出
B: 输出:b is an instance of A
C: 输出:b is an instance of C
D: 输出:b is an instance of Ab is an instance of C
答案: 【 输出:b is an instance of Ab is an instance of C】
13、单选题:
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 = new Cb(5); }} 运行代码,程序输出结果为:
选项:
A: 15
B: 52
C: 51
D: 编译错误
答案: 【 编译错误】
14、单选题:
下面关于继承的叙述正确的是?
选项:
A: Java中一个类只能实现一个接口
B: Java类中只允许单一继承
C: Java中一个类不能同时继承一个类和实现一个接口
D: Java中一个类可继承于多个类
答案: 【 Java类中只允许单一继承】
15、单选题:
下列程序的输出是()。class Other{ public Other () { System.out.print("Other!"); } } public class Driver1 extends Other { public static void main( String[] args ) { new Driver1(); new Other (); } }
选项:
A: Other!
B: Other!Other!
C: Other!Other!Other!
D: 编译错误
答案: 【 Other!Other!】
16、单选题:
请选出以下程序的输出结果public class Child extends People { People father; public Child(String name) { System.out.print(3); this.name = name; father = new People(name + ":F"); } public Child() { System.out.print(4); } public static void main(String[] args) { new Child("Alice"); }}class People { String name; public People() { System.out.print(1); } public People(String name) { System.out.print(2); this.name = name; }}
选项:
A: 123
B: 132
C: 32
D: 312
答案: 【 132】
17、单选题:
请选出正确答案class Parent { String one, two; public Parent(String a, String b){ one = a; two = b; } public void print(){ System.out.println(one); }}public class Child extends Parent { public Child(String a, String b){ super(a,b); } public void print(){ System.out.println(one + " to " + two); } public static void main(String arg[]){ Parent p = new Parent("south", "north"); Parent t = new Child("east", "west"); p.print(); t.print(); }}
选项:
A: 编译错误
B: south to northeast to west
C: south to northeast
D: southeast to west
答案: 【 southeast to west】
18、单选题:
请选择正确的输出结果class Guy { public Guy(){ System.out.print("111,"); }}class Cowboy extends Guy { public Cowboy(){ System.out.print("222,"); }}class Wrangler extends Cowboy { public Wrangler(){ System.out.print("333,"); }}public class Greeting2 { public static void main(String[] args) { Guy g1 = new Guy(); Guy g2 = new Cowboy(); Guy g3 = new Wrangler(); }}
选项:
A: 111,222,333,
B: 111,111,222,222,333,
C: 1
