Sun java认证考试答案
SUN认证是给网络设计界建立的一套认证标准,Sun公司推出了Java以及Solaris技术认证方案。小编收集一些Sun java认证考试真题答案,希望发夹认真做题!
1. What gets printed when the following program
is compiled and run?
class Test {
public static void main(String args[]) {
int i;
do {
i++;
} while (i < 0);
tln(i);
}
}
Select 1 correct answer:
A. The program does not compile as i is not initialized.
B. The program compiles but does not run.
C. The program compiles and runs but does not print anything.
D. The program prints 0.
E. The program prints 1.
答案:A:如果没有初始化便使用基本变量类型,会导致编译时异常,程序不能编译。
2. What gets printed when the following program
is compiled and run?
public class XYZ {
public static void main(String args[]) {
int i,j,k;
for (i = 0; i < 3; i++)
{
for(j=1; j < 4; j++)
{
for(k=2; k<5; k++)
{
if((i == j) && (j==k))
tln(i);
} } } } }
Select 1 correct answer:
A. 0
B. 1
C. 2
D. 3
E. 4
答案:C
3. Given the following code :
class Base{}
public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
static double d = 10.1;
public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}
Which of the following, if inserted at the comment //Here
will allow the code to compile and run without error?
Select 2 correct answers:
A. b = m;
B. m = b;
C. d = i;
D. b1 = i;
解析:A 从子类型到父类型的转换是扩展引用转换,不需要在运行时采取特殊的动作,不会在运行时抛出异常。
B 从超类型到子类型的'转换是收缩引用转换,需要在运行时执行测试,以查明实际的引用值是否是新类型的合法值.如果不是, 则会抛出ClassCascException 。在这里,b本身不是MyCast类型的值,因此会导致运行时异常。
C 从int到double的转换是扩展基本转换,基本类型之间的扩展转换永远不会导致运行时异常。但从int或long到float,或者是从long到double都可能导致精度丢失。
D 不允许进行int和boolean之间的类型转换
答案:A、C
4. Given the following classes which of the following
will compile without error?
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[])
{
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();
}
}
Select 3 correct answers:
A. o1 = o2;
B. b = ob;
C. ob = b;
D. o1 = b;
解析:A 任何对象都可以赋给Object类型的对象,正确
B 子类赋给超类是扩展引用转换,可以进行
C 收缩引用转换,错误
D 扩展引用转换,可以进行
答案 A B D
5. What is the result of compiling and running the following code?
1 public class Test {
2 static int total = 10;
3 public static void main (String args []) {
4 new Test();
5 }
6 public Test () {
7 tln("In test");
8 tln(this);
9 int temp = l;
10 if (temp > 5) {
11 tln(temp);
12 }
13 }
14 }
Select 1 correct answer:
A. The class will not compile
B. The compiler reports an error at line 2
C. The compiler reports an error at line 9
D. The value 10 is one of the printed elements
E. The class compiles but generates a runtime error
答案:D 由于test类没有override toString方法,故在调用println(this)时会直接显示类的有关信息。
6. Carefully examine the following code:
public class StaticTest {
static { tln("Hi there"); }
public void print() {
tln("Hello");
}
public static void main(String args []) {
StaticTest st1 = new StaticTest();
t();
StaticTest st2 = new StaticTest();
t();
}}
When will the string "Hi there" be printed?
Select 1 correct answer:
A. Never
B. Each time a new instance is created
C. Once, when the class is first loaded into the JVM
D. Only when the static method is called explicitly
答案 C
Java虚拟机规范约定,类的初始化发生在首次主动使用时。静态变量和静态初始化块的先后,实际上取决于它们在类中出现的先后顺序。
7. Given the following code what is the effect of a being 5?
public class Test {
public void add(int a) {
loop: for (int i = 1; i < 3; i++){
for (int j = 1; j < 3; j++) {
if (a == 5) {
break loop;
}
tln(i * j);
}
}
}
}
Select 1 correct answer:
A. Generates a runtime error
B. Throws an ArrayIndexOutOfBoundsException
C. Prints the values: 1, 2, 2, 4
D. Produces no output
解析:考察标记和break的使用。单纯使用break只跳出当前循环(一层)。如果在要跳出的循环前加标记,那么在加过标记的循环中的任何地方都可以使用break 标记 来跳出该循环
答案:D
-
2017年全国计算机等级考试开考科目及介绍
2017年全国计算机等级考试继续实行NCRE2013版考试大纲和新的证书认证体系,实施NCRE全部级别和科目的无纸化考试工作。下面是小编整理的关于计算机等级考试科目,希望可以帮助大家!级别考试科目考试教材考试时间一级计算机基础及WPSOffice应用计算机基础及WPSOffic...
-
2017年计算机等级程序设计上机操作题
c语言程序设计可以作为系统设计语言,编写工作系统应用程序,也可以作为应用程序设计语言,编写不依赖计算机硬件的应用程序。因此,它的应用范围广泛。下面是关于计算机等级程序设计上机操作题,欢迎大家参考!一、编程题请编写函数fun,其功能是:判断t所指字符串中的字母是...
-
2017年计算机应用能力考试题库
计算机系统实现自动维护和诊断的技术。实施维护诊断自动化的主要软件为功能检查程序和自动诊断程序。以下是关于计算机应用能力考试题库,希望大家认真阅读!1、要求:在当前添加一个默认组织结构图:答案:菜单插入→图片→组织结构图。2、要求:将当前幻灯片的...
-
2017年计算机二级office题库选择题
2017年3月计算机等级考试定于3月25日-28日举行,下面是小编整理的一些关于计算机二级office题库选择题,希望对各位考生有所帮助!1.程序流程图中带有箭头的线段表示的是()。A.图元关系B.数据流C.控制流D.调用关系答案:C【解析】在数据流图中,用标有名字的箭头表示数...