Java程序设计试卷及答案
- 格式:doc
- 大小:45.00 KB
- 文档页数:6
Java程序语言试卷(A) 答题卡:
一题:
1.___________________________________________________________
2.___________________________________________________________
3.___________________________________________________________
4.___________________________________________________________
5.___________________________________________________________
6.___________________________________________________________
四题:
1.___________________________________________________________
2.___________________________________________________________
3.___________________________________________________________
4.___________________________________________________________
5.___________________________________________________________五题:
一、阅读JA V A程序,写出运行结果。(30分,每小题5分)
1、public class ko5_2{
public static void main(String args[]) {
int x=20,y=30;
if (x>0)
if (x x - =10; else y + =10; System.out.print("x="+x); System.out.println(" y="+y); } } 请给出运行结果___________________________ 2、public class ko5_12{ public static void main(String args[]){ int t,z=10; t=sum(z); System.out.println("sum="+t); } static int sum(int x) { if (x==1) return(1); else return(sum(x-1)*x); } } 请给出运行结果___________________________ 3、interface ko6_7interface { float x=30.5f; float y=4.6f; float total(); } public class ko6_7 implements ko6_7interface { float dollar,money; ko6_7(float a,float b) {dollar=a;money=b;} public float total() {return x*dollar+money/y;} public static void main(String args[]) { ko6_7 z=new ko6_7(100,4600); System.out.print("美金="+z.dollar); System.out.print("人民币="+z.money); System.out.print("折合台币="+z.total()); } } 请给出运行结果___________________________ 4、class koA{ static int a; public void display(){ System.out.print(“ a=”+a); }} class ko13{ public static void main(String args[]){ koA a1=new koA; a1.a=10; koA a2=new koA; a2.a=20; koA.a=50; a1.dispay(); a2.display(); } } 请给出运行结果___________________________ 5、class A{ void callme(){ System.out.println(“Inside A’s callme() method”); }} class B extends A{ void callme(){ System.out.println(“Inside B’s callme() method”); }} public class Dispatch{ public static void main(String args[]){ A a=new B(); a. callme(); } } 请给出运行结果___________________________