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

当前位置:首页 > 《JAVA语言程序设计》期末考试试题题库2014 (整理版)

《JAVA语言程序设计》期末考试试题题库2014 (整理版)

  • 62 次阅读
  • 3 次下载
  • 2025/5/4 20:27:33

学习资料收集于网络,仅供参考

4、以下程序的输出结果_姓名:Tom 年龄:15 家庭住址:金水区 电话:66123456 学校:九中_。 public class Father {

String name, address, tel; int age;

public Father(String name, int age) {

5、下列程序的运行结果是__12345____。 public class MyClass {

int a[] = { 1, 2, 3, 4, 5 }; void out() {

for (int j = 0; j < a.length; j++) System.out.print(a[j] + \); }

this.name = name; this.age = age; }

void out() { System.out.print(\姓名:\ + name); System.out.print(\年龄:\ + age); }

void outOther() {

System.out.print(\家庭住址:\ + address);

System.out.print(\电话:\ + tel); } }

class Son extends Father { String school;

public Son(String name, int age) { super(name, age); }

void out() { super.out();

super.outOther();

System.out.println(\学校:\ + school); }

public static void main(String args[]) {

Son son = new Son(\, 15); son.address = \金水区\; son.school = \九中\; son.tel = \; son.out();

}

} 学习资料

public static void main(String[] args) {

MyClass my = new MyClass(); my.out(); }

}

6.运行下面的程序,输出并记录结果。 class Father{

private int f1,f2;

public Father(int f1,int f2) { this.f1=f1;this.f2=f2; }

public void print() {

System.out.println(\ } }

class Child extends Father { private int c1,c2;

public Child(int f1,int f2,int c1,int c2) { super(f1,f2);

this.c1=c1;this.c2=c2; }

public void print() { super.print();

System.out.println(\ } }

//增加的测试代码

public class XT003302 {

public static void main(String[] args) { Child c = new Child(1,2,3,4); c.print(); } } 输出:

f1=1 f2=2 c1=3 c2=4

学习资料收集于网络,仅供参考

7.请说出A类中System.out.println的输出结果。

class B{

int x=100,y=200;

public void setX(int x){

x=x; }

public void setY(int y){

this.y=y; }

public int getXYSum(){

return x+y; } }

public class A{

public static void main(String args[]){

B b=new B(); b.setX(-100); b.setY(-200);

System.out.println(\m()); } }

sum=-100

8.请说出A类中System.out.println的输出结果。

public class A{

public static void main(String args[]){

B b=new B(20); add(b);

System.out.println(b.intValue()); }

public static void add(B m){

int t=777;

m.setIntValue(t); } } 学习资料

class B {

int n; B(int n){

this.n=n; }

public void setIntValue(int n){

this.n=n; }

int intValue(){

return n; } } 777

9.请说出A类中System.out.println的输出结果。

public class A{

public static void main(String args[]){

Integer integer=new Integer(20); add(integer);

System.out.println(integer.intValue()); }

public static void add(Integer m){

int t=777;

m=new Integer(t); } } 20

10.请说出A类中System.out.println的输出结果。

class B{

int n;

static int sum=0; void setN(int n){

this.n=n; }

int getSum(){

for(int i=1;i<=n;i++)

学习资料收集于网络,仅供参考

sum=sum+i; return sum;

} }

public class A{

public static void main(String args[]){

class B extends A{//重载

double f(int x,int y){

return x*y; } }

public class E{

B b1=new B(),b2=new B(); b1.setN(3); b2.setN(5);

int s1=b1.getSum(); int s2=b2.getSum();

System.out.println(s1+s2); } } 21

11.请说出E类中System.out.println的输出结果。 class A {

double f(double x,float y){

return x+y; }

double f(float x,float y){

return x*y; } }

public class E{

public static void main(String args[]){

A a=new A();

System.out.println(\,10));

System.out.println(\,10.0F)); } }

**100.0 ##20.0

12.请说出E类中System.out.println的输出结果。

class A{

double f(double x,double y){

return x+y; } } 学习资料

public static void main(String args[]){

B b=new B();

System.out.println(b.f(3,5)); System.out.println(b.f(3.0,5.0)); } }

15.0 8.0

13.请说出E类中System.out.println的输出结果。

c1ass A{

double f(double x,double y){

return x+y; }

static int g(int n){

return n*n; } }

class B extends A{

double f(double x,double y){//重写

double m=super.f(x,y); return m+x*y; }

static int g(int n){

int m=A.g(n); return m+n; } }

public class E{

public static void main(String args[]){

B b=new B();

System.out.println(b.f(10.0,8.0)); System.out.println(b.g(3)); } }

98.0 12

14.请说出E类中System.out.printf的输出结果。

interface Computer{

int computer(int x,int y);

学习资料收集于网络,仅供参考

}

abstract class AA{

int computer(int x,int y){

return x-y; } }

class B extends AA implements Computer{

public int computer(int x,int y){

return x+y; } }

public class E{

public static void main(String args[]){

Computer com=new B(); AA a=new B();

System.out.printf(\,com.computer(12,10));

System.out.printf(\,a.computer(15,5)); }

22 20 学习资料

四、简答题

1.如果在D:\\MyJavaFile目录下有一个文件FirstJavaProgram.Java,写出在JDK环境下,此程序的运行过程。

答:运行过程:先切换到D:\\MyJavaFile目录,然后依次执行:

(1)javac FirstJavaProgram.Java (2)java FirstJavaProgram.class

2.什么叫面向对象编程?什么是对象?什么是类?

面向对象编程(Object-Oriented Programming ,OPP)是一套概念和想法,它与面向过程的编程方法相对应,是一种利用计算机程序来描述实际问题的思路,也是一种直观,效率更高的解决问题的方法。面向对象的程序设计方法按照现实世界的特点来管理复杂的事物,把它们抽象为对象,具有自己的状态和行为,通过对消息的反应来完成一定的任务。

对象就是变量和相关的方法的集合,其中变量表明对象的状态,方法表明对象所具有的行为,一个对象的变量构成这个对象的核心,包围在它外面的方法使这个对象和其它对象分离开来。

类是对一组具有相同特征的对象的抽象描述,所有这些对象都是这个类的实例。在程序设计语言中,类是一种数据类型,而对象是该类型的变量,变量名即是某个具体对象的标识名。

3.类的修饰符包括哪些?各起什么作用?

包括访问控制符(表示被访问权限)、抽象类说明符abstract(说明是否是抽象类)、最终类说明符final(表示是否是最终类)。

4.什么是抽象类?什么是抽象方法?抽象方法与普通方法有什么不同?

以abstract作为关键字,如果有的话,应该放在访问控制符后面,表示这个类是个抽象类。抽象类中至少包含一个抽象方法,抽象方法是只声明了方法名和参数而没有定义方法体的特殊方法。抽象类不能直接产生实例化一个对象,它只能被继承。

5.父类与子类是怎样建立关联的?如果父类和子类中都有一个同名的方法,在程序中调用这个方法,应该用什么关键字来区分?

父类与子类是通过继承和派生建立关联的,父类可以派生出子类,可以被子类继续,子类可以继续父类的属性和方法。

如果父类和子类中都有一个同名的方法,通过关键

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

学习资料收集于网络,仅供参考 4、以下程序的输出结果_姓名:Tom 年龄:15 家庭住址:金水区 电话:66123456 学校:九中_。 public class Father { String name, address, tel; int age; public Father(String name, int age) { 5、下列程序的运行结果是__12345____。 public class MyClass { int a[] = { 1, 2, 3, 4, 5 }; void out() { for (int j = 0; j < a.length; j++) System.out.print(a[j] + \); } this.name =

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价: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