资源描述
1、 试题序号:601
2、 题型:程序编写题
3、 难度级别:2
4、 知识点:类和对象的创建,结构函数(4-1)
5、 分值:10
6、 所需时间:15
7、 试题核心字:
8、 试题内容:
编写一个矩形类Rect,包括:
两个protected属性:矩形的宽width;矩形的高height。
两个结构器措施:
(1)一个带有两个参数的结构器措施,用于将width和height属性初化;
(2)一个不带参数的结构器,将矩形初始化为宽和高都为10。
两个措施:
(1) 求矩形面积的措施area()
(2) 求矩形周长的措施perimeter()
9、 答案内容:
class Rect{
protected double width,height;
public Rect(double width,double height){
this.width=width;
this.height=height;
}
public Rect(){
width=10;
height=10;
}
public double area(){
return width*height;
}
public double perimeter(){
return 2*(width+height);
}
}
10、 评分细则:
属性定义:3分;
结构器措施:3分;
措施实现:4分;
1、 试题序号:602
2、 题型:程序编写题
3、 难度级别:3
4、 知识点:类和对象的创建,结构函数(4-1)
5、 分值:10
6、 所需时间:15
7、 试题核心字:
8、 试题内容:
定义一个Person类,能够在应用程序中使用该类。
组员属性:Person类的属性(变量):
姓名:name,字符串类型:String;
性别:sex,字符型:char;
年龄:age,整型:int。
3个重载的结构函数:
public Person(String s) //设置姓名
public Person(String s,char c) //调用本类的结构函数Person(String s),设置性别
public Person(String s,char c,int i)//调用本类的结构函数PersonPerson(String s,char),设置年龄
一个组员措施:
public String toString()//取得姓名、性别和年龄
利用定义的Person类,请实例化对象,输出下面成果:
姓名:张三 性别:男 年龄:21
9、 答案内容:
public class Person
{
String name;
char sex;
int age;
public Person()
{}
public Person(String s)
{
name=s;
}
public Person(String s,char c)
{
this(s);
sex=c;
}
public Person(String s,char c,int i)
{
this(s,c);
age=i;
}
public String toString()
{
String s="姓名: "+name+" 性别:"+sex+" 年龄:"+age;
return s;
}
}
10、 评分细则:
类名、类申明正确 1分
属性定义正确1分
结构措施public Person(String s) 编写正确 2分
结构措施public Person(String s,char) 编写正确 2分
结构措施public Person(String s,char c,int i) 编写正确 2分
措施public String toString() 编写正确 2分
1、 试题序号:603
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:继承(5-4),多态(5-3)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
编写一个具备继承关系的java程序,要求如下:
a) 必须有this和super的使用;
b) 必须在程序中体现出措施的重载和覆盖.
9、 答案内容:
class child
{
child()
{
System.out.println("child default");
}
child(int i)
{
this();
System.out.println("int");
}
void f()
{
System.out.println("f()");
}
}
class Parent extends child
{
Parent()
{
super();
System.out.println("parent default");
}
Parent(int i)
{
super(i);
System.out.println("parent int");
}
void f()
{
System.out.println("parent f()");
}
}
public class Foo
{
public static void main(String[] args)
{
//Parent p = new Parent();
Parent p = new Parent(1);
p.f();
}
}
10、 评分细则:其中this和super的使用各占2分,继承的实现占2分,覆盖和重载各占2分。
1、 试题序号:604
2、 题型:程序编写题
3、 难度级别:3
4、 知识点:文献的输入输出(14-2)
5、 分值:10
6、 所需时间:15
7、 试题核心字:
8、 试题内容:
编写一个java程序,实现拷贝文献”test.txt”中的所有内容到”test1.txt”中.
9、 答案内容:
import java.io.*;
public class Foo
{
public static void main(String[] args)
{
try
{
String s=null;
FileReader fr = new FileReader("test.txt");
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter("test1.txt");
BufferedWriter bw = new BufferedWriter(fw);
while((s=br.readLine())!=null)
{
bw.write(s);
bw.flush();
bw.newLine();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
}
10、 评分细则:其中import语句占2分
Try语句块的书写占2分
FileReader和FileWriter的结构各占1分
复制语句的完成占3分
close语句的书写占1分
1、 试题序号:605
2、 题型:程序编写题
3、 难度级别:5
4、 知识点:抽象类,接口(5-5)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
编写一个java程序,其中包括最少一个抽象类以及一个接口,再定义一个类实现抽象类以及接口中的措施.
9、 答案内容:
interface A
{
int f();
}
abstract class B
{
abstract int g();
}
public class Foo extends B implements A
{
int a=2,b=1;
public int f()
{
return (a+b);
}
public int g()
{
return (a*b);
}
public static void main(String[] args)
{
Foo foo= new Foo();
System.out.println(foo.f());
System.out.println(foo.g());
}
}
10、 评分细则:接口定义正确得2分,抽象类定义正确得2分,继承抽象类并实现接口正确得2分。实现接口中的措施得2分,实现抽象类中的措施得2分
1、 试题序号:606
2、 题型:程序编写题
3、 难度级别:3
4、 知识点:基本输入输出流(14-1),while(3-2)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
编写一个java程序,实现从键盘输入一个整数,输出该整数的最高位数.
9、 答案内容:
import java.io.*;
public class Foo
{
public static void main(String[] args)
{
try
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
int i = Integer.parseInt(s);
while(i>10)
{
int j = i%10;
i=i/10;
}
System.out.println(i);
}catch(IOException e)
{
e.printStackTrace();
}
}
}
10、 评分细则:import语句占2分,try语句块占2分,从标准输入中读取整数代码段的实现占4分,计算占2分。
1、 试题序号:607
2、 题型:程序编写题
3、 难度级别:3
4、 知识点:java程序的运行步骤(1-4)
5、 分值:10
6、 所需时间:16
7、 试题核心字:
8、 试题内容:
分别用java application和java applet两种方式打印出”hello world”;
9、 答案内容:
public class Foo
{
public static void main(String[] args)
{
System.out.println("hello world");
}
}
import java.applet.Applet;
import java.awt.*;
public class Foo extends Applet
{
public void paint(Graphics g)
{
g.drawString("hello world",50,50);
}
}
10、 评分细则:其中application和Applet各占5分。在application中,类的定义正确占2分,main函数定义正确占2分,打印语句占1分。在applet中,import语句占1分,applet类的结构占2分,paint措施的书写占2分。
1、 试题序号:608
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:java程序的运行步骤(1-4)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
分别用application和Applet的方式写出打印HelloWorld的代码。并针对不一样的方式书写对应的运行命令。
9、 答案内容:
Public class Test
{
Public static void main(String[] args)
{
System.out.prinln(“Hello world”);
}
}
Javac Test.java
Java Test
import java.applet.Applet;
public class Test extends Applet
{
Public void paint(Graphics g)
{
g.drawString(“Helloworld”,20,20);
}
}
//<applet code=Test.class weight=300 height=300></applet>
javac Test.java
appletviewer Test.java
10、 评分细则:其中application和applet各占5分,在application中,代码的书写正确占3分,javac命令的书写正确占1分,java命令的书写正确占1分。在applet中,代码的书写占2分,html标签的书写占1分,javac命令的书写占1分,appletviewer的书写占1分。
1、 试题序号:609
2、 题型:程序编写题
3、 难度级别:3
4、 知识点:类和对象(4-1)
5、 分值:10
6、 所需时间:15
7、 试题核心字:
8、 试题内容:
写出一个Point(点)类,该类具备x,y(表示点的横、纵坐标)两个属性,并定义两个个结构措施,一个无参数,将x,y均设置为0,另一对坐标值为参数,设置x,y为给定坐标值。该类的show措施输出该点的坐标值。
9、 答案内容:
class Point
{ int x,y;
Point(){x =0;y=0;}
Point(int x,int y){this.x=x;this.y=y;}
public void Show(){System.out.print("坐标为:("+x+","+y+”)”);}
}
10、 评分细则:类的定义得1分,不带参数的结构函数的定义占3分,带参数的结构函数的定义占3分,show措施的书写占3分
1、 试题序号:610
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:类和对象,结构函数(4-1)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
设计并测试一个计算机类,它包括如下内容:
1. 该计算机包括属性:品牌,颜色,cpu型号,硬盘价格以及措施:打开,关闭
2. 为该计算机类书写一个不带参数的结构函数
3. 为计算机重载一个带参数的结构函数。
9、 答案内容:
public class Computer
{
String name;
String color;
String cpu;
int price;
public void open()
{
//.......
}
public void close()
{
//.........
}
public Computer()
{
//.......
}
public Computer(int name)
{
// ........
}
}
10、 评分细则:类的定义占2分,数据组员的书写占2分,组员措施的书写占2分,两个结构函数各占2分。
1、 试题序号:611
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:接口(5-5)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
定义一个接口Volume,其中包括一个计算机体积的抽象措施calculateVomume,然后设计cricle和Rectangle两个类都实现接口中的这个措施。分别结算球体和长方形得体积。
9、 答案内容:
interface Volume
{
float calculateVolume();
}
class Circle implements Volume
{
private float x;
private float y;
private float radius;
Circle(float x,float y,float radius)
{
this.x=x;
this.y=y;
this.radius=radius;
}
public float calculateVolume()
{
return ((float)Math.PI*radius*radius*radius*4/3)
}
}
class Rectangle implements Volume
{
private float length;
private float width;
private float height;
Circle(float length,float width,float height)
{
this.length=length;
this.width=width;
this.height=height;
}
public float calculateVolume()
{
return (length*width*height);
}
}
10、 评分细则:
接口的定义2分,两个类的定义各占2分,措施的实现各占2分
1、 试题序号:612
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:类和对象,结构函数(4-1)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
编写一个类实现银行账户(bank account)的概念。
1.银行账户的属性有“账号”、“储户姓名”、“储户身份证号”、“日期”、“金额”、“存款余额"、“累计余额"。银行账户的措施有“存款”、“取款"、等。
2.编写一个带有默认结构函数(也就是没有任何参数)的类,在其中显示某些信息,
然后为此类产生某些对象。
3.使用刚才定义的类创建几个实例,然后通过实例来访问其中的变量和措施来完成一定的功效。
9、 答案内容:
import java.util.*; j
class Account{
final int Max=5; //操作的次数
private int top; //储户账目管理的指针
private int Ac_id; //账号
private String Ac_name; // 储户姓名
private long Ac_card; //储户身份证号
private String Ac_date[]=new String[Max]; //日期t
private int Ac_money[]=new int[Max]; //金额
private int Ac rest[]=new int[Max]; //余额
private static int Ac_sum=0; //累计余额
public Account() //结构函数,设置各参数
{
top=0; //储户账目管理的指针
Ac_id=0; //账号
Ac_name=“”; //储户姓名
Ac_card=0; //储户身份证号
}
void Ac_in(String Ac_name,String aAc_date,int aAc_money) //存款措施
{
Ac_date[top[=aAc_date;
Ac_money[top]=aAc_money;
Ac_sum=Ac_sum+aAc_money;
Ac_rest[top]=Ac_sum;
System.out.println(“储户姓名”+Ac_name+“日期”+Ac_date[top]+ “存入”+
Ac_money[top]+ “存款余额”+Ac_rest[top]); .
top++;
}
void Ac_out(String Ac_name,String aAc_date,int aAc_money)//定义存款的方//法
{
Ac_date[top]=aAc_date;
Ac_money[top]=-aAc_money;
Ac_sum=Ac_sum-aAc_money; .
Ac_rest[top]=Ac_sum;
System.out.println(”储户姓名”+Ac_name+“日期”+Ac_date[top]+ “取出”+
(-Ac_money[top])+ “存款余额”+Ac_rest[top]);
top++;
}
}
puDllc class BankAccount
{
public static void main(String[】args)
{
//利用实例,调用储蓄用户
Account zhang=new Account();
zhang.Ac_in(“张梁”,“.6.6”,3000);
zhang.Ac_out(“张梁”,“.6.8”,),
zhang.Ac_in(“张梁”,“.7.7",3000);
zhang.Ac_out(“张梁",“.7.9”,1500);
}
}
10、 评分细则:其中类的定义1分,变量定义1分,2个措施定义各占2分。结构措施占2分,对措施的调用占2分。
1、 试题序号:613
2、 题型:程序编写题
3、 难度级别:3
4、 知识点:继承(5-4)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
编写一个Java应用程序,设计一个运输工具类Trartspoft,包括的组员属性有:速度、载重量;汽车类Vehicle是Transpoft的子类,其中包括的属性有:车轮个数和车重;飞机Airplane类是Transport的子类其中包括的属性有:机型和发动机数量,每个类都有有关数据的输出措施。
运输工具Transport是超类,Vehicle类和Airplane类是它的子类。在设计时将公共的
属性和措施放在超类Transport中。
9、 答案内容:
class Transport
{
int pace; //速度
float load; //载重量
Transport(int apace,float aload){
pace=apace;
load=aload;
void show()
{
System.out.println(“速度”+pace+“公里/小时”);
System.out.println(“载重量”+load+“Kkg”);
}
}
}
class Vehicle extends Transport //定义汽车类
{
int wheels; //车轮数
float weight; //车重量
Vehicle(int apace,float aload,int awheels,float aweight)
//汽车类的结构函数
{
super(apace,aload);
wheels=awheels;
weight=aweight,
}
void show() //显示属性
{
System.out.println(“交通工具:汽车”),
super.show(); //调用父类的显示措施
System.out.println(“车轮”+wheels+“个”);
System.out.println(“重量”+weight+“kg”);
System.out.println();
}
}
class Airplane extends Transport
//定义飞机Airplane类,飞机是Transport的子类,其中包括属性发动机类型和发动机数量
String enginertype;//发动机类型
int enginers;//发动机数量
Airplane(int apace,float aload,String aenginertype,int aenginers)
{
super(apace,aload);
enginertype=aenginertype();
enginers=aenginers;
}
void show() //显示属性
{
System.out.println(“交通工具:飞机”);
super.show(); //调用父类的显示措施
System.out.println(“飞机类型”+enginertype);
System.out.println(“发动机数量”+enginers);
}
}
10、 评分细则:第一个类的定义占1分,下面2个类的定义各占2分。3个类中的变量定义各占1分。用来数据输出的措施占2分
1、 试题序号:614
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:重载(5-3)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
撰写某个class,令它拥有一个重载了三次的函数。为它派生一个新得class,并为上述函数加入一份新的重载定义。证明这4个函数在派生类中都可用。
9、 答案内容:
class ThreeOverloads {
public void f(int i) {
System.out.println("f(int i)");
}
public void f(char c) {
System.out.println("f(char c)");
}
}
class MoreOverloads extends ThreeOverloads {
public void f(String s) {
System.out.println("f(String s)");
}
}
public class E13_InheritedOverloading {
public static void main(String args[]) {
MoreOverloads mo = new MoreOverloads();
mo.f(1);
mo.f('c');
mo.f("Hello");
}
}
10、 评分细则:父类的定义占1分。两个个重载的函数各占2分。子类的定义占1分,子类的新的重载函数占2分,在类中证明这些措施都能够用的语句占2分。
1、 试题序号:615
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:包(5-5),访问控制修饰符(5-2)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
撰写位于某个package内的某个类,令它含有一个protected函数。在此package之外,试着调用该protected函数。并解释其成果。
9、 答案内容:
import c06.protect.*;
class Derived extends ClassWithProtected {
public void g() {
f(); // 在子类中能够访问
}
}
public class E15_Protected {
public static void main(String args[]) {
//! ClassWithProtected().f(); // 不能访问
new Derived().g();
}
} ///:~
//: c06:protect:ClassWithProtected.java
package c06.protect;
public class ClassWithProtected {
protected void f() {
System.out.println("Protected Method");
}
}
10、 评分细则:程序必须定义三个类。其中有两个类在一个包中,剩余一个类在一个包中。包和类的定义共占5分。对protected函数的访问以及解释占5分
1、 试题序号:616
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:覆盖(5-3),继承(5-4)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
撰写一个base class。具备两个函数,并在第一个函数中调用第二个函数。然后,派生一个新的类,并于其中覆盖第二个函数。目前产生一个派生类对象,并将它向上转型到base class。并调用第一个函数。最后写出输出成果并对成果进行解释。
9、 答案内容:
class TwoMethods {
public void m1() {
System.out.println("Inside m1, calling m2");
m2();
}
public void m2() {
System.out.println("Inside m2");
}
}
class Inherited extends TwoMethods {
public void m2() {
System.out.println("Inside Inherited.m2");
}
}
public class E12_MethodCalls {
public static void main(String args[]) {
TwoMethods x = new Inherited();
x.m1();
}
}
成果是:Inside m1, calling m2
Inside Inherited.m2
因为第二个措施在子类中被覆盖。
10、 评分细则:程序的书写占7分,成果占2分,解释占1分。其中程序的书写中函数的覆盖占4分。其他占3分
1、 试题序号:617
2、 题型:程序编写题
3、 难度级别:4
4、 知识点:接口(5-5)
5、 分值:10
6、 所需时间:20
7、 试题核心字:
8、 试题内容:
撰写三个interface,每一个都有两个函数,撰写一个新得interface,继承上述三者,并新增一个函数。撰写一个class实现出那个新得interface,并继承另一个类。接下来写4个函数。各自接收上述4个interface之一作为参数。在main()措施中,为你的那个class产生对象。并将它传入上述4个函数中
9、 答案内容:
interface Interface1 {
void f1();
void g1();
}
interface Interface2 {
void f2();
void g2();
}
interface Interface3 {
void f3();
void g3();
}
interface Multiple
extends Interface1, Interface2, Interface3 {
void h();
}
class Concrete {
String s;
public Concrete(String s) {
this.s = s;
}
}
class All extends Concrete implements Multiple {
public All() {
super("All");
}
public void h() {
System.out.println("All.h");
}
public void f1() {
System.out.println("All.f1");
}
public void g1() {
System.out.println("All.g1");
}
public void f2() {
System.out.println("All.f2");
}
public void g2() {
System.out.println("All.g2");
}
public void f3() {
System.out.println("All.f3");
}
public void g3() {
System.out.println("All.g3");
}
}
public class E05_InterfaceInheritance {
public void takes1(Interface1 i) {
i.f1();
i.g1();
}
public void takes2(Interface2 i) {
展开阅读全文