這十道10道Java題你會做嗎?測驗你的水平
/**
*這10題都是我做過的,做錯或覺得需要複習的有價值的,整理出來也考考大家
*有更好的建議歡迎提出來
*/
1.程式碼輸出結果是
public class Test { public static void main(String [] args){ System.out.println(new B().getValue()); } static class A{ protected int value; public A(int v) { setValue(v); } public void setValue(int value){ this.value = value; } public int getValue(){ try{ value++; return value; } catch(Exception e){ System.out.println(e.toString()); } finally { this.setValue(value); System.out.println(value); } return value; } } static class B extends A{ public B() { super(5); setValue(getValue() - 3); } public void setValue(int value){ super.setValue(2 * value); } } }
A.11 17 34
B.22 74 74
C .6 7 7
D.22 34 17
2.下面的程式編譯運行後,螢幕上顯示的結果是()
public class test { public static void main(String args[]) {int x,y;x=5>>2;y=x>>>2;System.out.println(y);} }
A .0
B.2
C.5
D.80
3.有下列程式碼:請寫出程式的輸出結果。
public class Test { public static void main(String[] args) { int x = 0; int y = 0; int k = 0; for (int z = 0; z < 5; z++) { if ((++x > 2) && (++y > 2) && (k++ > 2)) { x++; ++y; k++; } } System.out.println(x + ”” +y + ”” +k); } }
A.432
B.531
C.421
D.523
4.以下程式碼結果為何?
public class foo { public static void main(String sgf[]) { StringBuffer a=new StringBuffer(“A”); StringBuffer b=new StringBuffer(“B”); operate(a,b); System.out.println(a+”.”+b); } static void operate(StringBuffer x,StringBuffer y) { x.append(y); y=x; } }
A.程式碼可以編譯運行,輸出「AB.AB」。
B.程式碼可以編譯運行,輸出「A.A」。
C.程式碼可以編譯運行,輸出「AB.B」。
D.程式碼可以編譯運行,輸出「A.B」。
5.給以下程式碼,請給結果. 0608
class Two{ Byte x; } class PassO{ public static void main(String[] args){ PassO p=new PassO(); p.start(); } void start(){ Two t=new Two(); System.out.print(t.x+””); Two t2=fix(t); System.out.print(t.x+” ” +t2.x); } Two fix(Two tt){ tt.x=42; return tt; } }
A.null null 42
B.null 42 42
C.0 0 42
D.0 42 42
6. 下列程式碼片段中,存在編譯錯誤的語句是()
byte b1=1,b2=2,b3,b6,b8; final byte b4=4,b5=6,b7; b3=(b1+b2); /*语句1*/ b6=b4+b5; /*语句2*/ b8=(b1+b4); /*语句3*/ b7=(b2+b5); /*语句4*/ System.out.println(b3+b6);
A.語句2
B.語句1
C.語句3
D.語句4
7.What will be printed when you execute the following code? 0611
class C { C() { System.out.print("C"); } } class A { C c = new C(); A() { this("A"); System.out.print("A"); } A(String s) { System.out.print(s); } } class Test extends A { Test() { super("B"); System.out.print("B"); } public static void main(String[] args) { new Test(); } }
A.BB
B.CBB
C.BAB
D.None of the above
#8.以下程式碼執行後輸出結果為( )0611
public class ClassTest{ String str = new String("hello"); char[] ch = {'a','b','c'}; public void fun(String str, char ch[]){ str="world"; ch[0]='d'; } public static void main(String[] args) { ClassTest test1 = new ClassTest(); test1.fun(test1.str,test1.ch); System.out.print(test1.str + " and "); System.out.print(test1.ch); } }
A.hello and dbc
B.world and abc
C.hello and abc
D.world and dbc
9.以下程式碼將會列印出
public static void main (String[] args) { String classFile = "com.jd.". replaceAll(".", "/") + "MyClass.class"; System.out.println(classFile); }
A.com. jd
B.com/jd/MyClass.class
C.///////MyClass.class
D.com.jd.MyClass
#10.對於如下程式碼段
class A{ public A foo(){return this;} } class B extends A{ public A foo(){ return this; } } class C extends B { _______ }
可以放入到橫線位置,使程式正確編譯運行,而且不產生錯誤的選項是( )
A.public void foo(){}
B.public int foo(){return 1;}
C.public A foo(B b){return b;}
D.public A foo(){return A;}
相關文章:
相關影片:
#以上是這十道10道Java題你會做嗎?測驗你的水平的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

公司安全軟件導致部分應用無法正常運行的排查與解決方法許多公司為了保障內部網絡安全,會部署安全軟件。 ...

系統對接中的字段映射處理在進行系統對接時,常常會遇到一個棘手的問題:如何將A系統的接口字段有效地映�...

在使用MyBatis-Plus或其他ORM框架進行數據庫操作時,經常需要根據實體類的屬性名構造查詢條件。如果每次都手動...

將姓名轉換為數字以實現排序的解決方案在許多應用場景中,用戶可能需要在群組中進行排序,尤其是在一個用...

在使用IntelliJIDEAUltimate版本啟動Spring...

Java對象與數組的轉換:深入探討強制類型轉換的風險與正確方法很多Java初學者會遇到將一個對象轉換成數組的�...

電商平台SKU和SPU表設計詳解本文將探討電商平台中SKU和SPU的數據庫設計問題,特別是如何處理用戶自定義銷售屬...

在使用TKMyBatis進行數據庫查詢時,如何優雅地獲取實體類變量名以構建查詢條件,是一個常見的難題。本文將針...
