云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > Java期末复习练习题2014版

Java期末复习练习题2014版

  • 62 次阅读
  • 3 次下载
  • 2025/6/6 18:27:30

J=100;

Systerm.out.println(“j=”+j); }

Public static void main (String[] args){

Systerm.out.println(“InitDemo.j=”InitDemo.j”); InitDemo aa=new InitDemo(); InitDemo.j=500;

Systerm.out.println(“aa.j=”+aa.j); }}

答:j = 100

InitDemo.j = 100 i = 5 j = 10 j = 1000 aa.j = 500

32.

class Animal{

public Animal(){

System.out.println(“I’m an animal”); } }

class Bird extends Animal{ public Bird(){

System.out.println(“I’m a bird.”); } }

public class AnimalTest{

public static void main(String[]args){ Bird b = new Bird(); } }

运行结果为: I'm an animal I'm a bird.

33. class A{ int x,y;

void setXY(int x,int y){ this.x = x; this.y = y; }

int multiply(){ return x * y; } }

class B extends A{ int x,z;

B(int x,int z){

super(); this.x =x; this.z =z; }

int multiply(){ return x * y * z; } }

public class ABTest{

public static void main(String[]args){ A a = new B(5,10);//x=5,z=10 a.setXY(10,20);//x=10,y=20

System.out.println(\ B b=new B(6,9);//x=6.z=9 b.setXY(7,8);//x=7,y=8 b.z=10;//z=10

System.out.println(\ } }

运行结果为: m=1000 m=480

34.class Parent{ void printMe(){

System.out.println(\ } }

class Child extends Parent{ void printMe(){

System.out.println(\}

void printAll(){ super.printMe(); this.printMe(); printMe(); } }

public class Test{

public static void main(String[]args){ Child myC = new Child(); myC.printAll(); } }

运行结果为: I'm a parent. I'm a child. I'm a child.

Press any key to continue... 34.

abstract class AA{

abstract void callme(); void metoo(){

System.out.println(\ } }

class BB extends AA{ void metoo(){

System.out.println(\ }

void callme(){

System.out.println(\ } }

public class AbstractTest{

public static void main(String[]args){ AA aa = new BB(); aa.callme(); aa.metoo(); } }

运行结果:

Inside BB's callme. Inside BB's metoo.

Press any key to continue... 35.

class Employee{}

class Manager extends Employee{} class Secretary extends Employee{} class Programmer extends Employee{} public class Test24{ public static void method(Employee e){ if (e instanceof Manager) System.out.println(\ else if (e instanceof Secretary) System.out.println(\else if (e instanceof Programmer) System.out.println(\ }

public static void main(String[] args){ Manager m = new Manager(); Secretary s = new Secretary(); Programmer p = new Programmer(); method(m); method(s); method(p); } }

输出结果为:

He is a Manager. He is a Secretary. He is a Programmer.

36.

public class Test{

public static void main(String [] args){ try{

for(int i = 3 ; i >= 0 ; i--){

System.out.println(\System.out.println(6 / i); }

}catch(ArithmeticException ae){ System.out.println(\ } }

}

输出结果为:

The value of i : 3 2

The value of i : 2 3

The value of i : 1 6

The value of i : 0 Divided by zero. 37.

public class Foo{ public static void method(int i){ try{ if(i >0){ return; }else{ System.exit(1); } } finally{ System.out.println(\ }

public static void main(String [] args){ method(5); method(-5); } }

输出结果为:

Finally

38.

public class Test1{

public static String output=\public static void foo(int i){ try {

if(i==1){

throw new Exception(); }

output +=\

}catch (Exception e){ output +=\return ; }finally{

output +=\}

output +=\}

public static void main(String[] args){ foo(0); foo(1);

System.out.println(\

搜索更多关于: Java期末复习练习题2014版 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

J=100; Systerm.out.println(“j=”+j); } Public static void main (String[] args){ Systerm.out.println(“InitDemo.j=”InitDemo.j”); InitDemo aa=new InitDemo(); InitDemo.j=500; Systerm.out.println(“aa.j=”+aa.j); }} 答:j = 100 InitDemo.j = 100 i = 5 j = 10 j = 1000 aa.j = 500 32. class Animal{ public Animal(){ System.out.pri

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com