JAVA复习题继承 下载本文

内容发布更新时间 : 2024/4/30 18:03:22星期一 下面是文章的全部内容请认真阅读。

public static void main( String args[] ) {

int a1=1234,a2=456; int MaxValue;

MaxValue=____________; 二个数的最大值:\ }

public static ______ max(int x,int y) { int max_value; max_value =x>y?x:y; return max_value; } }

10.下面是一个类的定义,请将其补充完整。(class static___________ Bank { String s;

_____ int a=666;

Bank(String s1) { s=s1; } static int geta( ) { return a; }

) }

三、程序阅读题

1.下面是一个类的定义,根据题目要求回答以下问题. class B {

private int x;

private char y;

public B(int i,char j) { }

public void show() {

x=i; y=j;

+\

}

public void methodC(int x) {

this.x=this.x+x;

y++;

}

}

show();

(1)定义类B的一个对象b,将类中的变量x初始化为10、变量y初始化为’A’,请写出相应的语句。(B b=new B(10,’A’);) (2)若在(1)问基础上有方法调用语句: b.show();

则输出如何?(x=10; y=A)

(3)若在(1)问基础上增加语句: b.methodC(1); 则输出为何?(x=11; y=B) (x=11; y=B)

2.阅读程序,回答问题。 public class Test52 {

String static str1=\ String static str2=\ public static void main(String args[]) }

问题:1)这是哪种形式的 java 程序 ?(java应用程序) 2)程序的输出是什么?

(Hello, Java world! Hello, students! ) 3. 写出下列程序的输出结果 public class Test {

public static void main(String[] args) {

Count myCount = new Count(); int times = 0; for(int i=0;i<100;i++)

increment(myCount , times);

“count is” + myCount.count); “time is”+ times); }

}

public static void increment(Count c , int times) { }

c.count++; times++;

class Count { } } 答案: count 101 times 0

4.写出下列程序的输出结果: public class Test {

public static void main(String[] args) public int count; Count(int c) { } Count() {

count =1; count =c;