Java英文面试必备:题目与答案解析

5星 · 超过95%的资源 需积分: 10 114 下载量 14 浏览量 更新于2024-07-29 3 收藏 120KB DOC 举报
"这是一份关于Java编程的英文笔试题集,包含了答案,适用于准备外企面试的求职者。" 1. Java数据类型与转换 - Question1) 提到了几种Java基本数据类型的赋值情况: - 1) `float f=1.3;` 这行代码会编译通过,因为Java会自动将double类型的小数转换为float。 - 2) `char c="a";` 不会编译通过,因为char类型只能存储单个字符,而"a"是字符串。 - 3) `byte b=257;` 不会编译通过,因为byte的范围是-128到127,257超出了范围。 - 4) `boolean b=null;` 不会编译通过,因为boolean类型不能赋null值。 - 5) `int i=10;` 编译通过,这是有效的int类型赋值。 2. 方法调用与主方法 - Question2) 关于主方法调用非静态方法的问题: - 如果尝试在主方法中调用非静态方法`amethod`,编译器会报错,因为非静态方法需要对象实例才能调用。 - 1) "error Can't make static reference to void amethod." 是正确的编译错误信息,表示不能对非静态方法进行静态引用。 3. 包和导入 - Question3) 关于包和导入语句的正确使用: - 1) 的包声明和导入语句在同一行,不遵循Java规范,不会编译通过。 - 2) 的顺序是正确的,先包声明,后导入,会编译通过。 - 3) 在注释之后放置包声明是不合法的,但导入语句和类声明都是正确的,所以这个例子会编译通过。 4. 字节类型范围 - Question4) 提到了byte类型的取值范围: - 正确的答案是1) `-128 to 127`,这是因为byte在Java中占8位,其值域是-2^7(即-128)到2^7-1(即127)。 5. 字符串操作与数组越界 - Question5) 涉及到运行时的代码行为,可能包含一个未给出的代码片段,通常会打印出数组的引用和尝试访问数组第二个元素时抛出的异常。 这些题目覆盖了Java的基础知识,包括数据类型、方法调用、包和导入规则、数值范围以及运行时错误处理。对于准备Java面试或笔试的求职者来说,理解和掌握这些概念是非常重要的。学习并解决这些问题有助于巩固对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 .....