SUN认证考试面试题
SUN认证是给网络设计界建立的一套认证标准,Sun公司推出了Java以及Solaris技术认证方案。以下是小编整理的关于SUN认证考试面试题,希望大家认真练习!
1.Which of the following fragments might cause errors?
A. String s = "Gone with the wind";
String t = " good ";
String k = s + t;
B. String s = "Gone with the wind";
String t;
t = s[3] + "one";
C. String s = "Gone with the wind";
String standard = s.toUpperCase();
D. String s = "home directory";
String t = s - "directory";
answer:(BD)这道题考察java字符串和连接符+的理解,B中s[3]是一个字符,而不能和一个字符串用连接符连起来。而D则是我们初学java时以为有+必定有-,所以导致错误。java中的连接符只有一个就是+。而且字符串和字符是两个不同的概念,我们要区分开来。
2. Given the following code fragment:
1) public void create() {
2) Vector myVect;
3) myVect = new Vector();
4) }
Which of the following statements are true?
A. The declaration on line 2 does not allocate memory space for the variable myVect.
B. The declaration on line 2 allocates memory space for a reference to a Vector object.
C. The statement on line 2 creates an object of class Vector.
D. The statement on line 3 creates an object of class Vector.
E. The statement on line 3 allocates memory space for an object of class Vector
answer:(ADE)这题考察获得实例的内存变化。定义一个实例并不能给对象分配内存空间,系统只给定义的那个变量分配空间。只有当new 出一个对象时系统回给一个实例对象分配内存空间。
3. Which are not Java keywords?
A. TRUE
B. sizeof
C. const
D. super
E. void
answer:(AB)sizeof是c++语言的的关键字,不是java的,我做题的时候觉得sizeof很熟悉,想当然以为它就是java的关键字,结果可想而知。
4. Which are not Java primitive(基本) types?
A. short
B. Boolean
C. unit
D. float
answer:(BC)java基本数据类型只有8个,而Boolean是引用数据类型。选错了,关键是没弄清primitive是什么意思,汗颜啊,英语太差了。
5. Which statements about the garbage collection are true?
A. The program developer must create a thread to be responsible for free
the memory.
B. The garbage collection will check for and free memory no longer needed.
C. The garbage collection allow the program developer to explicity and
immediately free the memory.
D. The garbage collection can free the memory used java object at expect
time.
answer:(B)java垃圾自动回收机制,我们不能让虚拟机什么时候开始垃圾回收,垃圾回收是不受我们控制的,就算我们想要快点垃圾回收,我们只能通过一个gc()函数希望快点垃圾回收,但是程序回不回提前垃圾回收还是不知道的。所以选b。
6、Which of the following assignment is not correct?
A. float f = 11.1;
B. double d = 5.3E12;
C. double d = 3.14159;
D. double d = 3.14D.
answer:(A)记住基本数据类型中int和double都是默认的,所以a是错的,把double转换成float型要强制类型转换。第一次碰到这样的题的时候我全错,不过现在好了。
7、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).
answer:(C)这题有较大迷惑,要是不认真看,估计会选d,看看参数列表是n和a,如果选择d的话就错了。
8、public void test() {
try { oneMethod();
System.out.println("condition 1");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("condition 2");
} catch(Exception e) {
System.out.println("condition 3");
} finally {
System.out.println("finally");
}
}
Which will display if oneMethod run normally?
A. condition 1
B. condition 2
C. condition 3
D. finally
answer:(AD)finally 修饰的最终都将会运行,所以当程序正常运行,不抛出异常时,AD都将运行。
9 Given the following code fragment:
1) String str = null;
2) if ((str != null) && (str.length() > 10)) {
3) System.out.println("more than 10");
4) }
5) else if ((str != null) & (str.length() < 5)) {
6) System.out.println("less than 5");
7) }
8) else { System.out.println("end"); }
Which line will cause error?
A. line 1
B. line 2
C. line 5
D. line 8
answer:(C)&&和&的区别,&是按位与计算,&两边的运算都要执行;&&是逻辑运算,当左边为假时,右边可以不执行。当右边执行时,可能有 (str.length()空指针异常)。
10、Given the following code:
public class Person{
static int arr[] = new int[10];
public static void main(String a[]) {
System.out.println(arr[1]) ;
}
}
Which statement is correct?
A. When compilation some error will occur.
B. It is correct when compilation but will cause error when running.
C. The output is zero.
D. The output is null.
answer:(C)java数组默认初始化都为0.
11、Given the following code:
public class Person{
int arr[] = new int[10];
public static void main(String a[]) {
System.out.println(arr[1]);
}
}
Which statement is correct?
A. When compilation some error will occur.
B. It is correct when compilation but will cause error when running.
C. The output is zero.
D. The output is null.
answer:(A)这道题看起来跟前一个题一样,但是仔细看的话这次的'数组没有声明为static,所以静态main方法不能直接调用,所以编译时会有错误。
12、Which fragments are correct in Java source file?
A. package testpackage;
public class Test{//do something...}
B. import java.io.*;
package testpackage;
public class Test{// do something...}
C. import java.io.*;
class Person{// do something...}
public class Test{// do something...}
D. import java.io.*;
import java.awt.*;
public class Test{// do something...}
answer:(ACD)关于包的引用等。包必须在impotr的前面,既是包在最上面。可以没有包的声明。
13:String s= "hello";
String t = "hello";
char c[] = {h,e,l,l,o} ;
Which return true?
A. s.equals(t);
B. t.equals(c);
C. s==t;
D. t.equals(new String("hello"));
E. t==c.
answer:(ACD)这是String,s和t没有new 所以只是声明了两个变量,ACD都正确。
14、public class Parent {
public int addValue( int a, int b) {
int s;
s = a+b;
return s;
}
}
class Child extends Parent {
}
Which methods can be added into class Child?
A. int addValue( int a, int b ){// do something...}
B. public void addValue (){// do something...}
C. public int addValue( int a ){// do something...}
D. public int addValue( int a, int b )throws MyException {//do something...}
answer:(BC)涉及到方法的重写和覆盖,三同一不低,A是默认的,但是父类是public的,不满足不低的原则。看题要仔细。
【SUN认证考试面试题】相关文章: