java复习资料_第1页
java复习资料_第2页
java复习资料_第3页
java复习资料_第4页
java复习资料_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1、阅读以下程序,输出结果为 。 class Q1 public static void main(String args double d=1.23; Dec dec =new Dec(); dec.decreme nt(d); System.out.pri ntl n( d); classs Dec public void decreme nt(double decMe) decMe = decMe 0.1; 2、以下程序段的输出结果为 class Crun cher void crun ch( int i ) System.out.pri ntl n( void crun ch(Stri

2、 ng s) System.out.pri ntl n( public static void main(String args ) Cruncher int version ); String version ” ); char ch= crun.crun ch(ch); crun=new P; Crun cher (); 3、阅读以下程序段: class Pare nt void prin tMe() System.out.println(“pt ” ); class Child exte nds Pare nt void prin tMe() System.out.print (“cd”

3、 ); void prin tAll() super.pri ntMe(); this.pri ntMe(); prin tMe(); public class Test_this public static void main(String args) Child myC=new Child(); myC.pri ntAII(); 输出结果为 。 4、已有Bird类的定义如下: package abcde; public class Bird protected static int referen ceCo un t=0; public Bird() referen ceCo un t+;

4、 protected void fly() static int getReCo unt() return referenceCount; 有类 Night in gale的定义如下,请写出它的输出结果 packagesin gers ; class Night in gale exte nds abcde.Bird Night in gale() referen ceCo un t+; public static void main( String args) System.out.print( “ Before: ” +referenceCount); Nighti ngale flore

5、 nce=new Nighti ngale(); System.out.pri ntl n(“ After:” +refere nceCo un t); flore nce.fly(); 5、 以下程序段的输出结果为 。 public class test public static void main(String args) Strin gBuffer s = new Strin gBuffer(Hello); s.appe nd(there); System.out.pri ntl n( s); String pf = s.substring(0, s.length(); System.

6、out.pri ntln( pf.equals(Hellothere); 6、 以下程序段的输出结果为 。 class Pers on public Pers on() System.out.pri ntl n(hi!); public Person( Stri ng s) this(); System.out.println(I am +s); public class Who exte nds Person public Who() this(I am Tony); public Who(Stri ng s) super(s); System.out.println(How do you

7、do?); public static void main(String args) Who w = new Who(Tom); 7. 下面是一个类的定义。 class/ 定义名为 MyClass的类 int var=666; static int getvar() retur n var; x.show(); class SuperClass int a,b; SuperClass(i nt aa , int bb) a=aa; b=bb; void show() System.out.pri ntln (a=+a+nb=+b); class SubClass exte nds SuperC

8、lass int c; SubClass(i nt aa,i nt bb,i nt cc) super(aa,bb); c=cc; class SubSubClass exte nds SubClass int a; SubSubClass(i nt aa,i nt bb,i nt cc) super(aa,bb,cc); a=aa+bb+cc; void show() System.out.pri ntln( a=+a+inb=+b+nc=+c); 9.以下程序的输出结果为 class Pers on public Person。 System.out.pri ntln (Pers on);

9、 class Stude nt exte nds Person publid Stude nt() System.out.pri ntl n( Stude nt); class CollegeStude nt exte nds Stude nt public CollegeStude nt() System.out.pri ntln (CollegeStude nt); public class Test public static void main( Stri ng args) CollegeStude nt cs=new CollegeStude nt(); 10 .通过键盘输入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=0;i-) System.out.pri nt( ai+); System.out.pri ntl n(); 11.以下程序的输出结果为 。 public class EqualOrNot public static void main(String args) B b1= new B(5); B b2=new B(5); Sy

11、stem.out.pri ntln( b1=b2); System.out.pri ntln( b1.equals(b2); class B int x; B(i nt y) x=y; 12 以下程序的输出结果为 class Pare nt void prin tMe() System.out.pri ntl n(pare nt); class Child exte nds Pare nt void prin tMe() System.out.pri ntln (child); void prin tAll() super.pri ntMe(); this.pri ntMe(); prin t

12、Me(); b public class Test_this public static void main(String args) Child myC=new Child(); myC.pri ntAll(); 13 以下程序的输出结果为 classCrun cher voidcrun ch(int i ) System.out.print( “int ” ); voidcrun ch(Stri ngs) System.out.print( “String ” ); args) public static voidmain( Stri ng Crun cher crun=new Crun

13、cher (); charch= h; inti=12; crun.crun ch(ch); System.out.print( “, ” ); crun.crun ch(i); 14 阅读以下程序: import java.io.*; public class AboutFile public static voidmain( Stri ng args) BufferedReader b=new BufferedReader (new InputStreamReader( System.i n); Stri ng s; System.out.flush(); try s=b.readL in

14、 e(); System.out.println(“Stringis: ” +s); Catch(IOException e) System.out.pri ntln( e.getMessage(); 运行以上程序,若从键盘输入:java回车 则输出结果为 15 写出以下程序的运行结果。 public class TryCatchFi nally static void Proc( int sel ) try if(sel=0 ) System.out.pri ntln (” noExcepti on); return; else if(sel=1 )int i=0; int j=4/i; p

15、ublic catch(ArithmeticExceptio n System.out.pri ntln( Catch”); catch( Excepti on e ) System.out.pri ntln (Willnot fin ally System.out.pri ntl n(fin ally); e ) be executed); static void main( String args ) Proc( 0); Proc( 1); 输出结果为: 15 阅读以下程序,写出输出结果。 class An imal An imal() System.out.pri nt(A nimal ); public class Dogexte ndsAni mal Dog() System.out.pri nt(Dog ); public static voidmain( Stri ngargs) Dogsn oppy=new Dog(); 输出结果为: 。 编程题 1、 编写一个类,要求该类实现一个接口,该接口有3个abstract方法: public abstract void f(int x); public abstract void g(i nt x, int y); public abstract double h

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论