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 ed 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虛擬機規範約定,類的初始化發生在首次主動使用時。靜態變量和靜態初始化塊的先後,實際上取決於它們在類中出現的先後順序。
相關文章
-
Sun java認證考試答案
SUN認證是給網絡設計界建立的一套認證標準,Sun公司推出了Java以及Solaris技術認證方案。小編收集一些Sun java認證考試真題答案,希望髮夾認真做題!1. What gets printed when the following programis compiled and run -
SUN認證Java2程序員考試題及答案
Java帶給你的並不僅僅是面向對象、開放、平臺無關、易用、安全和Write once, run anywhere等軟件開發方面的優勢,更重要的一點是,它提供了一種新穎的表達思想的方式,一種全新的思維模式。下面一起來看看Java2程序員考試 -
2017年SUN-Java程序員認證考試題庫及答案
Sun公司遠沒有當年AT&T和 IBM 那樣的好運氣,後者一個主流產品可以銷售十幾年。下面是小編整理的 關於SUN_Java程序員認證考試題庫及答案,希望大家認真閱讀!1.下列哪項不是JDK所包含的內容?(選一項)編程語言B.工具 -
sun java認證考試題庫
SCJP測驗Java程序設計概念及能力,內容偏重於Java語法及JDK的內容。下面是yjbys小編收集一些sun java認證考試題庫,希望大家認真閱讀!1.下列哪項不是JDK所包含的內容?(選一項)編程語言B.工具及工具的API EE擴展API平臺虛 -
SUN-Java認證考試題庫
Sun認證Java程序員考試旨在考察通過應用軟件分配進行復雜編程的能力。以下是小編整理的SUN_Java程序員認證考試題庫,希望大家認真閱讀!1.下列哪項不是JDK所包含的內容?(選一項)編程語言B.工具及工具的API EE擴展API平 -
SUNJava程序員認證考試題庫
Sun認證Java程序員考試旨在觀察您通過應用軟件分配進行復雜編程的能力,之後還要測試您完成編程所需的知識。以下是小編整理的關於SUNJava程序員認證考試題庫,希望大家認真閱讀!1.下列哪項不是JDK所包含的內容?(選一項) -
Sun-Java程序員認證考試題庫
日子如同白駒過隙,我們的工作同時也在不斷更新迭代中,現在的你想必不是在做計劃,就是在準備做計劃吧。相信大家又在爲寫計劃犯愁了?以下是小編爲大家整理的秋季二年級班主任工作計劃,供大家參考借鑑,希望可以幫助到有需要的 -
sun認證java程序員考試題庫
sun公司名稱的由來很多人不知道,它其實是斯坦福大學校園網(Stanford University Network)的首字母縮寫。下面是小編整理的sun認證java程序員考試題庫,歡迎大家參考!1.下列哪項不是JDK所包含的內容?(選一項)編程語言B.工 -
sun認證java程序員須知Java日誌框架
作爲一名Java程序員,明確的知道日誌系統是一個成熟Java應用所必不可少的,在開發和調試階段,日誌可以幫助我們更好更快地定位bug;在運行維護階段,日誌系統又可以幫我們記錄大部分的異常信息,從而幫助我們更好的完善系統。下 -
Sun認證Java程序員(SCJP)考試
Sun Microsystems在行業中被認爲是同行中最具創造性的企業之一,它想嘗試新的軟件方式和定價模式等等。下面是小編整理的關於Sun認證Java程序員(SCJP)考試,歡迎對大家參考! Java程序員(SCJP)考試科目簡介考試方式: 全