Java笔试试题:字符、浮点数与数组声明解析

需积分: 9 6 下载量 35 浏览量 更新于2024-09-13 1 收藏 46KB DOC 举报
Java是一种广泛使用的面向对象编程语言,其笔试题目主要考察了基础数据类型、字符处理、浮点数声明、数组定义以及多维数组的使用。以下是对这些知识点的详细解析: 1. **字符类型(Char)**: 在Java中,`char` 是一个16位的Unicode字符,通常用单引号 `'` 或 `\u` (Unicode escape sequence) 来声明。选项 A、C 和 F 是有效的 `char` 声明: - A: `char c1 = 064770;` 这是一个八进制形式,虽然Java不直接支持八进制,但可以通过手动转换来实现。 - C: `char c3 = 0xbeef;` 这是十六进制形式,正确地声明了一个 `char`。 - F: `char c6 = '\uface';` 这是正确的 Unicode 字符表示。 2. **字符范围**:Java的 `char` 类型实际上是一个 Unicode 编码,其数值范围是0到65535,所以答案是 E。 3. **浮点数类型(Float)**:Java的 `float` 类型用于表示带有小数部分的数字。合法的声明包括: - A: `float f1 = -343;` 浮点数可以表示负数。 - B: `float f2 = 3.14;` 表示常规浮点数。 - D: `float f4 = 42e7;` 使用科学记数法表示。 4. **数组声明**:Java中的数组声明需要注意大小和类型。合法的声明是: - A: `int[] myScores[];` 这是一个一维数组,但没有指定大小,可以随后初始化。 - B: `char[] myChars;` 一个字符数组,同样可以后续指定大小。 - D: `Dog[] myDogs;` 这是一个数组,可以存储Dog类型的对象,但未指定大小,可以动态扩展。 5. **多维数组示例(C部分)**: 在这段代码中,定义了一个三维整数数组 `x`,并用嵌套循环创建数组元素。在第10行,`x[i][j]` 的赋值使用的是 `i+j+1`,这会导致数组长度在每次循环时递增,这不是有效的数组操作。正确的做法是预先定义每个维度的大小。 Java英文笔试题涵盖了字符类型、数值范围、浮点数声明、数组定义及其操作等基础概念,这些知识点在实际编程中非常重要,能够体现应聘者的语法掌握程度和对基本数据结构的理解。
2008-12-21 上传
1. The name of a Java source file (a) has no restrictions (b) must be the same as the class it defines, ignoring case (c) must use the extension .class (d) must be the same as the class it defines, respecting case 2. Which of the following statements is (are) true about the use of an asterisk (*) in a Java import statement? Ⅰ.It does not incur run-time overhead. Ⅱ.It can be used to import multiple packages with a single statement. Ⅲ.It can be used to import multiple classes with a single statement (a) I, II, and III (b) I and III only (c) I only (d) III only ..... 9. According to the Java code conventions, files that contain Java source code have the suffix _____, and compiled bytecode files have the suffix _____. (a) .class, .java (b) .class, .javac (c) .java, .class (d) .javac, .class 10. As an aid in debugging a program in Java, print statements may be used to display which of the following types of information? I. The names of methods being called II. The values of the parameters of a method Ⅲ. The values of the instance variables of a class (a) I and II only (b) I and III only (c) II and III only (d) I, II, and III 1. In a UML class diagram's representation of a class, the top, middle, and lower rectangular compartments respectively describe the _____ of the class. (a) name, attributes, and methods (b) name, methods, and constants (c) attributes, methods, and name (d) attributes, methods, and constants 2. UML class diagrams can describe which of the following? I. The internal structure of classes Ⅱ. Relationships between classes (a) I and II (b) II only (c) None (d) I only ....... 1.The term class variable is a synonym for (a) a private data field (b) a static data field (c) a read-only variable (d) an instance variable 2. Consider the following Java program segment. import java.io.*; public class Test { public Test( ) { System.out.println("default"); } public Test( int i ) { System.out.println("non-default"); } public static void main(String[] args) { Test t = new Test(2); } } ......... 9. When a subclass defines an instance method with the same return type and signature as a method in its parent, the parent's method is said to be (a) private (b) hidden (c) overloaded (d) overridden 10. Which is a Java access modifier used to designate that a particular data field will not be inherited by a subclass? (a) final (b) protected (c) private (d) default 1. Consider the following Java program segment. String[] str = {"Three","Two","One"}; for (int i = 0; i < str.length; ++i) { System.out.println(str[i]+"/"); } What will be output upon execution of the program segment? (a) Three/Two/One/ (b) Three,Two,One (c) One,Two,Three (d) One/Two/Three/ 2. Consider the following Java program segment. int[] arr; arr = new int[3]; arr[2]=19; arr[1]=17; arr[0]=15; Which of the following Java statements is syntactically correct and semantically identical to the program segment? (a) int[] arr= {15, 17, 19}; (b) int[3] arr = {15, 17, 19}; (c) int arr = {15, 17, 19}; (d) int arr[3]= {15, 17, 19}; ........ 2. Which of the following statements is (are) true about any abstract method in Java? I. It contains no definition. Ⅱ. It cannot be declared public. (a) I and II (b) I only (c) None (d) II only 3. Consider the following Java program fragment. public void drive(Vehicle v) { ... } ... drive(obj); The method call drive(obj) is valid if obj is which of the following? I. A descendent of class Vehicle II. An ancestor of class Vehicle Ⅲ. An object of class Vehicle (a) I and III only (b) I, II, and III (c) III only (d) II and III only .....