




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、1、閱讀以下程序,輸出結果為 。class Q1public static void main(String args )double d=1.23;Dec dec=new Dec( );dec.decrement(d);System.out.println(d);classs Decpublic void decrement(double decMe)decMe = decMe 0.1;2、以下程序段的輸出結果為 。class Cruncher void crunch( int i ) System.out.println(“int version”); void crunch(String
2、 s) System.out.println(“String version”); public static void main(String args ) Crunchercrun=new Cruncher ( ); char ch=p; crun.crunch(ch); 3、閱讀以下程序段:class Parentvoid printMe()System.out.println(“pt”);class Child extends Parentvoid printMe()System.out.print (“cd”);void printAll()super.printMe();this.
3、printMe();printMe();public class Test_thispublic static void main(String args )Child myC=new Child();myC.printAll();輸出結果為 。4、已有Bird類的定義如下:package abcde;public class Bird protected static int referenceCount=0; public Bird() referenceCount+; protected void fly() static int getReCount() return referenc
4、eCount; 有類Nightingale的定義如下,請寫出它的輸出結果 。package singers;class Nightingale extends abcde.Bird Nightingale( ) referenceCount+;public static void main( String args ) System.out.print(“Before:”+referenceCount); Nightingale florence=new Nightingale( ); System.out.println(“ After:”+referenceCount); florence
5、.fly( );5、以下程序段的輸出結果為 。public class testpublic static void main(String args ) StringBuffer s = new StringBuffer("Hello"); s.append("there"); System.out.println(s); String pf = s.substring(0, s.length(); System.out.println(pf.equals("Hellothere"); 6、以下程序段的輸出結果為 。class Pe
6、rson public Person() System.out.println("hi!"); public Person(String s) this(); System.out.println("I am "+s); public class Who extends Person public Who() this("I am Tony"); public Who(String s) super(s); System.out.println("How do you do?"); public static vo
7、id main(String args) Who w = new Who("Tom"); 7下面是一個類的定義。class _ / 定義名為MyClass的類 _ int var=666; static int getvar() return var; 8以下程序的輸出結果為 。public class abc public static void main(String args ) SubSubClass x = new SubSubClass(10 , 20 , 30); x.show(); class SuperClass int a,b; SuperClass(i
8、nt aa , int bb) a=aa; b=bb; void show( ) System.out.println("a="+a+"nb="+b); class SubClass extends SuperClass int c; SubClass(int aa,int bb,int cc) super(aa,bb); c=cc; class SubSubClass extends SubClass int a; SubSubClass(int aa,int bb,int cc) super(aa,bb,cc);a=aa+bb+cc; void sh
9、ow() System.out.println("a="+a+"nb="+b+"nc="+c); 9以下程序的輸出結果為 。class Person public Person() System.out.println("Person"); class Student extends Person publid Student() System.out.println("Student"); class CollegeStudent extends Student public CollegeS
10、tudent() System.out.println("CollegeStudent"); public class Test public static void main(String args) CollegeStudent cs=new CollegeStudent(); 10通過鍵盤輸入10個整數,并按輸入的倒序輸出這10個整數。import java.io.*;public class Reverse public static void main(String args) int i,n=10; int a=new int10; for (i=0;i<
11、n;i+) try BufferedReader br=new BufferedReader( ); ai=Integer.parseInt( ); /輸入一個整數 catch(IOException e); for(i=n-1;i>=0;i-) System.out.print(ai+" "); System.out.println(); 11以下程序的輸出結果為 。public class EqualOrNot public static void main(String args) B b1=new B(5); B b2=new B(5); System.out
12、.println(b1=b2); System.out.println(b1.equals(b2); class B int x; B(int y) x=y; 12以下程序的輸出結果為 。class Parent void printMe() System.out.println("parent"); class Child extends Parent void printMe() System.out.println("child"); void printAll() super.printMe(); this.printMe(); printMe(
13、); bpublic class Test_this public static void main(String args) Child myC=new Child(); myC.printAll(); 13以下程序的輸出結果為 。class Crunchervoid crunch( int
14、 i ) System.out.print(“int”); void crunch(String s) System.out.print(“String”); public static void main(String args )Cruncher crun=new Cruncher
15、160;( );char ch=h;int i=12;crun.crunch(ch); System.out.print(“,”);crun.crunch(i); 14閱讀以下程序:import java.io.*;public class AboutFile public static void main(
16、String args) BufferedReader b=new BufferedReader (new InputStreamReader(System.in); String s; System.out.flush();
17、0; try s=b.readLine(); System.out.println(“String is:”+s); Catch(IOException e) System.out.println(e.getMessage(); 運行以上程序,若從鍵盤輸入: java<回車>則輸出結果為 。15寫出以下程序的運行結果。public
18、 class TryCatchFinally static void Proc( int sel ) try if( sel=0 )System.out.println("
19、;no Exception "); return; else if( sel=1 ) int i=0; int j=4/i;
20、0; catch( ArithmeticException e ) System.out.println("Catch "); catch( Exception e ) System.out.p
21、rintln("Will not be executed"); finally System.out.println("finally"); public static void main( String args ) Proc( 0 ); Proc( 1 ); 輸出結果為: 。15閱讀以下程序,寫出輸出結果。class Animal Animal() System.out.print ("Animal
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
評論
0/150
提交評論