您的位置:首页 » 期末试卷答案 » Java语言程序设计期末试卷 » Java语言程序设计 基础篇 英文版 第六版 期末试卷及答案 ([美 ]Y. Daniel Liang)

Java语言程序设计 基础篇 英文版 第六版 期末试卷及答案 ([美 ]Y. Daniel Liang)

Java语言程序设计 基础篇 英文版 第六版 期末试卷及答案 ([美 ]Y. Daniel Liang) - 封面

期末试卷配套教材:

书名:Java语言程序设计 基础篇 英文版 第6版
作者:[美 ]Y. Daniel Liang
出版社:机械工业出版社

期末试卷概述:

Java期末复习题 Choice Questions. Inheritance means ______________. that data fields should be declared private. that a class can extend another class. that a variable of supertype can refer to a subtype object. that a class can contain another class. Which of the statements regarding the super keyword is incorrect? You can use super to invoke a super class constructor. You can use super to invoke a super class method. You can use super.super.p to invoke a method in superclass?s parent class. Which of the following statements is false? Use the private modifier to encapsulate data fields. Encapsulating data fields makes the program easy to maintain. Encapsulating data fields makes the program short. Encapsulating data fields helps prevent programming errors. Which of the following statements is false? local variables do not have default values. data fields have default values. A variable of a primitive type holds a value of the primitive type. You may assign an int value to a reference variable. Which of the following statements is false about an immutable object? The contents of an immutable object cannot be modified. All properties of an immutable object must be private. All properties of an immutable object must be of primitive types. An object type property in an immutable object must also be immutable. Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate. x contains an array of ten int values. x contains an array of ten objects of the Circle type. x contains a reference to an array and each element in the array can hold a reference to a Circle object. x contains a reference to an array and each element in the array can hold a Circle object. You can declare two variables with the same name in __________. a method one as a formal parameter and the other as a local variable a block two nested blocks in a method different methods in a class Which of the following statement is false? A default no-arg constructor is provided automatically if no constructors are explicitly declared in the class. At least one constructor must always be defined explicitly. Constructors do not have a return type, not even void. Constructors must have the same name as the class itself. The method _____ overrides the following method. protected double xMethod(int x) {…}; public double xMethod(int x) {…} protected int xMethod(double x) {…} public double xMethod(double x) {…} private double xMethod(int x) {…} Analyze the following code. Which of the following statement is false? public class Test { public static void main(String[] args) { String s = new String("Welcome to Java"); Object o = s; String d = (String)o; } } s, o, and d reference the different String objects. When assigning s to o in Object o = s, no new object is created. When casting o to d in String d = (String)o, no new object is created. When casting o to d in String d = (String)o, the contents of o is not changed. Analyze the following code. Suppose that f is an instance of Foo. Which of the following statements is correct? class Foo { int i; static int s; void imethod() { } static int smethod() { return s; } } System.out.println(Foo.i); System.out.println(f.i); int t = f.imethod(); int t = Foo.imethod(); Analyze the following code: class Test { private int t; public static void main(String[] args) { Test test = new Test(); int x; System.out.println(x); } } The variable t is not initialized and therefore causes errors. The variable t is private and therefore cannot be accessed in the main method. The variable x is not initialized and therefore causes errors. The program compiles and runs fine. Analyze the following code: public class A { public static void main(String args[]) { int[] a = new int[10]; int[] c = new int[20]; a = c; } } The program has a compilnation error. The program has a runtime error. The program has a logic error. The program compiles and runs fine. Analyze the following code: class Circle { private double radius; public Circle(double radius) { radius = radius; } } The program has a compilation error because it does not have a main method. The program has a compilation error because you cannot assign radius to radius. The program does not compile because Circle does not have a default constructor. The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0. Given the following code: class C1 {} class C2 extends C1 { } class C3 extends C1 { } class C4 extends C2 {} C1 c1 = new C1(); C2 c2 = new C2(); C3 c3 = new C3(); C4 c4 = new C4(); Which of the following expressions evaluates to false? c1 instanceof C1 c2 instanceof C1 c3 instanceof C2 c4 instanceof C2 Suppose s1 and s2 are two strings. Which of the following statements or expressions are incorrect? String s3 = s1 - s2; String s3 = s1 + s2; int i = s1.compareTo(s2); char c = s1.char