java复习资料含答案

String name; int age; Student( ⑸ s, int i) { name=s; age=i; } }

⑴ Myclass ⑵ i ⑶ j ⑷Student ⑸ String

3、下面程序的结果是什么?

class Tester { int var;

Tester(double var) {

this.var = (int)var; }

Tester(int var) { this(\ }

Tester(String s) { this();

System.out.println(s); }

Tester(){

System.out.println(\ }

public static void main(String[] args) { Tester t = new Tester(5); } }

程序运行结果为:good-bye

hello

4、什么是类成员,什么是实例成员?他们之间有什么区别? 5、抽象类和接口有什么区别? 6、类与对象的关系是什么? 7、Java的访问限定修饰符有几种,各自的访问权限是什么? 8、写出下面代码所捕获的异常类型及程序运行的结果。

public class Exception1{

public static void main(String args[]){ try{ int a[]={1,2,3,4,5}, sum=0;

for(int i=0;i<=5;i++)sum=sum+a[i]; System.out.println(“sum=”+sum); }

catch(ArrayIndexOutOfBoundsException e){

System.out.println(“ArrayIndexOutOfBoundsExceptiondetected”); }

finally{

System.out.println(“Programm Finished!!”) } } }

答案:ArrayIndexOutOfBoundsExceptiondetected

Programm Finished!!

9、写出下面代码所捕获的异常类型及程序运行的结果。

public class Exception2 {

public static void main(String args[]){ try{ int x,y;

x=15;y=0;

System.out.println(x/y);

System.out.println(“Computing successfully!”); }

catch(ArithmeticException e){

System.out.println(“ArithmeticException catched!”) System.out.println(“Exception message:”+e.toString()); }

finally{

System.out.println(“Finally block.”) } } }

答案:ArithmeticException catched!

Exception message:java.lang.ArithmeticException: / by zero Finally block.

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4