JAVA期末复习资料 联系客服

发布时间 : 星期四 文章JAVA期末复习资料更新完毕开始阅读38b00f7d6c85ec3a87c2c5f7

A、setSize()

B、setDefaultClose() C、pack()

D、setVisible() 三、程序阅读题

1、阅读下面的程序: class test {

public static void main(String[] args) {

int i = 1; int All = 0; for (;i<=10;i++) {

if (i%6==0) break;

if(i%2==0) {i=i+2;continue;} All = All + i; }

System.out.println(All); } }

上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,运行结果是什么?

2、写出下列程序代码的运行结果: public class Example{

String str=new String(\ char ch[]={'J','a','v', 'a'};

public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.println(ex.str);

System.out.println(new String(ex.ch)); }

public void change(String str,char ch[]){ str=\ch[0]= 'Y'; } }

3、仔细阅读下面的程序代码,编译和运行后,请写出该程序的输出结果。 class Game {

Game(int i) {

System.out.println(\ } }

class BoardGame extends Game { BoardGame(int i) { super(i);

System.out.println(\ } }

public class Chess extends BoardGame { Chess() {

super(11);

System.out.println(\ }

public static void main(String[] args) { Chess x = new Chess(); } }

4、仔细阅读下面的程序代码,编译和运行后,请写出该程序的输出结果。 import java.util.*; class Instrument {

protected void play() { System.out.println(\ static void tune(Instrument i) { i.play(); } }

// Wind object are instruments

// because then have the same interface: class Wind extends Instrument {

protected void play() { System.out.println(\ public static void main(String[] args) { Wind flute = new Wind(); Instrument.tune(flute); } }

5、仔细阅读下面的程序代码,编译和运行后,请写出该程序的输出结果。 interface Product {

static final String MAKER = \ static final String PHONE = \ public int getPrice(int id); }

class Shoe implements Product { public int getPrice(int id) { if ( id == 1 ) return 5; else

return 10; }

public String getMaker() { return MAKER; } }

public class Store { static Shoe hightop;

public static void init() { hightop = new Shoe(); }

public static void main(String[] args) { init();

getInfo(hightop); orderInfo(hightop); }

public static void getInfo(Shoe item) {

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

public static void orderInfo(Product item) {

System.out.println(\+ \

System.out.println(\ } }

6、仔细阅读下面的程序代码,编译和运行后,请写出该程序的输出结果。 class Father{

String name=\ int age=45; int getAge(){ return age; }

String getName(){ return name; }

void setAge(int a){ age = a; } }

class Child extends Father{ String name=\ int age=18;

int getAge(){ return age+1; } }

class Test2{

public static void main(String args[]){ Father p=new Child();

System.out.println(p.getAge()); p.setAge(30); System.out.println(p.getAge());

System.out.println(p.getName()); } }

7、阅读下面的程序:

1) public class test 2) {

3) public static void main(String args[]) 4) {

5) Bird.Fly(3); 6) } 7) }

8) class Bird{ 9) int Type = 2;

10) private static void Fly(int an_Type){ 11) Type = an_Type;

12) System.out.println(\13) } 14) }

上面的程序编译是否成功?如果编译出错,指出哪行出错,并说明理由;如果编译正确,运行结果是什么? 8、阅读下面程序: class Person{

public Person(){

System.out.println(\ }

public Person(String s){ this();

System.out.println(\ } }

public class Who extends Person{ public Who(){

this(\