2014秋季Java程序设计期末考试试卷(A卷)课件

loading 分享 2026-9-4 下载文档

3.(5分)

public class Abc{

public static void main(String[] args){ int[] a = {1,2,3,4,5,6,7,8,9};

装订线 System.out.printf(\ }

static int odds(int[] a){ int s = 0;

for(int i = 0;i

return s; } }

4.(6分) public class A{

public A(){System.out.println(\ public void abc(){System.out.println(\}

class B extends A{

public B(){this(\

public B(String s){System.out.println(\ public void abc(){System.out.println(\ }

class C extends B{

public C(){this(\

public C(String s){System.out.println(\ public void abc(){super.abc(); System.out.println(\ }

public class Test{

public static void main(String args[]){

A a = new C(); a.abc(); }

(1)在程序中,a.abc()调用体现了面向对象的什么技术?(2分) (2)写出程序运行的结果(4分)

5

得分

四、编写程序题(本大题共3小题,共30分)

1. 设S = 1 + 2 + 3 + …,编写程序求出满足S < 5000的S的最大值。(9分)

2. 编写方法double avg(int[] a),求数组a中能被2或3整除的数的平均值,并在main方法中调用测试该方法。(9分)

3. 编写一个日期类Date,具体要求如下:(12分)

(1)数据域:

year表示年,month表示月,day表示日,类型均为int。封装数据域,并提供访问 器和修改器。 (2)构造方法:

默认构造方法Date(),默认值为2000年1月1日。 一般构造方法Date(int year,int month,int day)。

(3)改写toString方法,显示一个日期,格式为“今天是:XXXX年XX月XX日”。 (4)编写计算闰年中任意月份包含天数的方法int getDays()。

6


2014秋季Java程序设计期末考试试卷(A卷)课件.doc 将本文的Word文档下载到电脑
搜索更多关于: 2014秋季Java程序设计期末考试试卷(A卷)课件 的文档
相关推荐
相关阅读