JAVA程序员考试试题(8)

2019-01-07 11:34

public static void main(String args[ ]) {

System.out.println(\ }

}

class SubClass extends SuperClass { int c;

SubClass(int aa, int bb, int cc) {

super(aa, bb);

c=cc; } }

class SubSubClass extends SubClass { int a;

SubSubClass(int aa, int bb, int cc) { super(aa, bb, cc); A = aa+bb+cc; } void show() {

System.out.println(\ }

}

运行结果:a=60

b=20 c=30 class StringTest1 {

public static void main(String[] args) {

String s1=\

String s2=new String(\

1.以下程序的输出结果为 相等 。

}

}

if(s1.equals(s2)){ }

System.out.println(\相等\System.out.println(\不相等\}else{

2.以下程序段的输出结果为 5 6 7 8 9 。

public class TestArray {

public static void main(String args[ ]){

int i , j ;

int a[ ] = { 5,9,6,8,7}; int k = i;

for ( j = i ; j < a.length ; j++ )

if ( a[j]

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

}

for ( i =0 ; i

System.out.print(a[i]+\ \

System.out.println( ); } }

3.写出以下程序的功能。

import java.io.*; public class TestFile {

public static void main(String args[]) throws Exception {

BufferedReader br = new BufferedReader(

new InputStreamReader(System.in));

BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt\ String s; while (true)

{

System.out.print(\请输入一个字符串: \ System.out.flush(); s=br.readLine(); if (s.length()==0) break; bw.write(s); bw.newLine(); } bw.close(); } }

功能:从键盘逐一输入字符串,逐一输出至input.txt文件中,直至输入空行。

4.阅读以下程序,写出输出结果。

class Animal { Animal() {

System.out.print (\ \ } }

public class Dog extends Animal { Dog() {

System.out.print (\ }

public static void main(String[] args) { Dog snoppy= new Dog(); } }

输出结果:Animal Dog

五、程序设计题

1、按以下要求编写程序

(1) 创建一个Rectangle类,添加width和height两个成员变量 (2) 在Rectangle中添加两种方法分别计算矩形的周长和面积 (3) 编程利用Rectangle输出一个矩形的周长和面积 解答:

public class Rectangle { }

float width, height;

public Rectangle(float width, float height) { }

public float getLength(){ }

public float getArea(){ }

public static void main(String [] args) {

Rectangle rect = new Rectangle(10, 20);

System.out.println(\周长是:\ + rect.getLength()); return this.width * this.height; return (this.width + this.height) * 2; this.width = width; this.height = height;

System.out.println(\面积是:\ + rect.getArea()); }

2、按以下要求编写程序

(1) 编写Animal接口,接口中声明run() 方法 (2) 定义Bird类和Fish类实现Animal接口

(3) 编写Bird类和Fish类的测试程序,并调用其中的run()方法 解答:

public interface Animal { }

class Bird implements Animal {

public void run() {

System.out.println(\鸟儿在飞...\); }

void run();

}

class Fish implements Animal { }

public void run() {

System.out.println(\鱼儿在游...\); }

public class TestAnimal { }

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

Bird bird = new Bird(); bird.run();

Fish fish = new Fish(); fish.run();

3、编写一个Frame框架应用程序,要求如下:

(1) 在窗口设置两个菜单“文件”、“编辑”

(2) 在“文件”菜单里添加三个菜单项“打开”、“保存”、“关闭” (3) 在“编辑”菜单里添加两个菜单项“复制”、“粘贴” (4) 点击关闭菜单项时,使程序关闭。 解答:

import java.awt.Color; import java.awt.Frame; import java.awt.Menu; import java.awt.MenuBar; import java.awt.MenuItem;

import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; /* * 主窗体 */

public class MyFrame extends Frame {

private static final long serialVersionUID = 6895463895656626294L;

private Frame frmMain; // 窗体 MenuBar mb;

// 菜单栏


JAVA程序员考试试题(8).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:大一计算机考试试题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: