第一范文网 - 专业文章范例文档资料分享平台

JAVA期末复习和答案(1)

来源:用户分享 时间:2025/5/25 10:22:40 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

super(); x=8;

System.out.println(\+x); }

void doPrint(){ super.doPoint();

System.out.println(\+super.x+\+x); } }

in subClass():x=8 super.x=3 sub.x=8

4、在右边的矩形框中写出该程序运行的结果。

class StaticTest {

static int x=1; int y;

StaticTest() { y++; }

public static void main(String args[ ]){ StaticTest st=new StaticTest(); System.out.println(\

System.out.println(\ st=new StaticTest();

System.out.println(\} static { x++;} }

5、写出下列程序的运行结果

class Time1{

private int hour; private int minute; private int second; public Time1(){ setTime(0,0,0); }

public Time1(int hh){ setTime(hh,0,0); }

public Time1(int hh,int mm){ setTime(hh,mm,0); }

public Time1(int hh,int mm,int ss){ setTime(hh,mm,ss); }

public String toString(){

retunr (hour+\ } }

public class MyTime1{

private static Time1 t0,t1,t2,t3;

public static void main(String[] args){ t0=new Time1(); t1=new Time1(11); t2=new Time1(22,22); t3=new Time1(33,33,33);

System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ }

}

答案:t0=0:00:00 t1=11:00:00 t2=22:22:00 t3=0:33:33

6、在右边的矩形框中写出该程序运行的结果。

public class TestArray

{ public static void main(String args[ ]){ int i , j ;

int a[ ] = {1,3,2,5,4};

for ( i = 0 ; i < a.length-1; i ++ ) { int k = i;

for ( j = i ; j < a.length ; j++ ) if ( a[j]>a[k] ) k = j; int temp =a[i]; a[i] = a[k];

a[k] = temp; }

for ( i =0 ; i

答案:5、4、3、2、1

7、写出下列程序的运行结果

public class Exam {

public static void main(String[] args) {

int x=5; int m=0;

x+=x++ +(x++ +m); System.out.println(x);

} }

答案:16

8、在右边的矩形框中写出该程序运行的结果。

class MyException extends Exception{

答案:

private int detail;

MyException( int a ){ detail = a;}

public String toString( ){ return \}

public class ExceptionDemo{

public static void compute(int a) throws MyException { System.out.println(\ if( a>10 ) throw new MyException(a); System.out.println(\} public static void main( String args[] ){

try{ compute(6 ); compute( 12 ); }

catch( MyException e ){ System.out.println(\}

}

normal exit

called compute(12) Caught MyException 12

9、试标识出下面的QQ类中的所有无效语句(用下划线标示出),对每个无效语句说出其无效的理由。

class QQ{

private int alpha; private int beta;

public static void classMethod(){

this.beta=this.alpha*2; //beta和alpha不是静态. }

public QQ(){ //无返回值,应该用void QQ(0,0); } public QQ(int x,int y){ //无返回值,应该用void

alpha=this.x; //应该是this.alpha=x;this.beta=y; beta=this.y; } }

10、在右边的矩形框中写出该程序运行的结果。

class OverloadDemo{

void testOverload( int i ){

System.out.println(“int”); } void testOverload(String s){

System.out.println(“String”); } public static void main(String args[ ]){ OverloadDemo a=new OverloadDemo ( ); char ch=’x’;

a.testOverload(ch); } }

答案:int

11、写出下列程序的运行结果

public class Text { }

public int t=4;

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

public void NumberPlay(){ }

int t=2; t=t+5;

this.t=this.t-2; t=t-this.t;

System.out.print(t+\); System.out.println(this.t); new Text().NumberPlay();

答案:5 2

12、在右边的矩形框中写出该程序运行的结果。

class First{

public First(){

aMethod(); } public void aMethod(){

System.out.println(“in First class”);} }

public class Second extends First{ public void aMethod(){

System.out.println(“in Second class”);}

public static void main(String[ ] args){ new Second( ); } }

答案:in Second class

13、设计实现地址概念的类Address。Address具有属性:省、市、街道、门牌号、邮编,具有能设置和获取属性的方法。

14、请将下列程序补充完整

下列程序定义一个表示圆形的类,能够计算园面积和周长

class MyCircle{ float r;

final double PI=3.14159;

public double area(){ //计算面积 return PI*r*r; }

public void setR(float x){ //设置半径 r=x; }

搜索更多关于: JAVA期末复习和答案(1) 的文档
JAVA期末复习和答案(1).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4d4b29qk4f507xn0vysu_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top