45、 对象是类的一个实例。( √ ) 46、 若源程序文件以B.java命名,编译后只生成一个名为B.class的字节码文件。( × ) 47、 Java程序对计算机硬件平台的依赖性很低。( √ ) 48、 可以使用MouseListener接口处理焦点事件。( × ) 49、 构造函数与类名同名,没有返回值类型,功能用来初始化一个类的具体对象。√ 50、 Java语言的标识符必须由字母、下划线(_)或美元符($)开始,其余字符可以
是上述3种字符或数字(0~9)。√ 51、 Java语言中的布尔型boolean只有两个取值,即true和false,且不能和其他任
何类型转换。√ 52、 在swing用户界面的程序设计中,容器不能被添加到其它容器中去。( × ) 53、 Java类中可以存在同名的两个成员函数。( √ ) 54、 实现一个接口,则在类中一定要实现接口中的所有方法。( √ ) 55、 Java标识符不区分大小写,不能以数字开头,不能插入空格等。× 56、 在Java语言中声明数组时,无论用何种方式定义数组,都要指定其长度。× 57、 String类对象创建之后可以再修改和变动。× 58、 对于运行时异常,程序中一般可不做处理,由Java虚拟机自动进行处理。√ 59、 StringBuffer类对象创建之后可以再修改和变动。√ 60、 random()用于处理大数据。( × )
三、 阅读题
1. 请给出下面程序的输出结果
class Rect {
double width,height,area;
void setWidth(double width) { if(width>0){
this.width=width; } }
void setHeight(double height) { if(height>0){
this.height=height; } }
double getWidth(){ return width; }
double getHeight(){ return height; }
int getArea(){
area=width*height; return (int)area; } }
public class Example5_14 {
public static void main(String args[]) { Rect rect=new Rect(); double w=12.76,h=25.28; rect.setWidth(w); rect.setHeight(h);
System.out.println(\矩形对象的宽:\高:\ System.out.println(\矩形的面积:\
System.out.println(\更改向对象w,h变量的值为100和256\ w=100; h=256;
rect.setWidth(w); rect.setHeight(h);
System.out.println(\矩形对象的宽:\高:\ System.out.println(\矩形的面积:\ } } 答:
矩形对象的宽:12.76 高:25.28 矩形的面积:322
更改向对象的方法参数传递值的w,h变量的值为100和256 矩形对象的宽:100.0 高:256.0 矩形的面积:25600
2. 请给出下面程序的输出结果
class Tree { int height; Tree() { System.out.println(\ height = 0; } Tree(int initialHeight) { height = initialHeight; System.out.println(\ } void info() { System.out.println(\ } void info(String s) {
System.out.println(s + \ } }
public class Overloading {
public static void main(String[] args) { for(int i = 0; i < 2; i++) {
Tree t = new Tree(i); if (i==0) {
t.info(); } else {
t.info(\ } }
new Tree(); } }
答:
Creating new Tree that is 0 feet tall Tree is 0 feet tall Creating new Tree that is 1 feet tall overloaded method: Tree is 1 feet tall Planting a seedling
3. 请给出下面程序的输出结果
public class Example9_9 {
public static void main (String args[ ]) { String regex=\ String str1=\ String str2=\
System.out.println(str1.length()+str2.length()); if(str1.matches(regex)) {
System.out.println(str1+\可以表示数字\ } else {
System.out.println(str1+\不可以表示数字\ String result=str1.replaceAll(\ System.out.println(str1); System.out.println(result);
}
if(str2.matches(regex)) { System.out.println(str2); } else {
System.out.println(str2);
String result=str1.replaceAll(\ System.out.println(str2); System.out.println(result); } } } 答: 16 12r34a5不可以表示数字 12r34a5 12345 123.45908
4. 请给出下面程序的输出结果
class Anthropoid { double m=12.58;
void crySpeak(String s) { System.out.println(s); } }
class People extends Anthropoid { char m='A'; int n=60;
void computer(int a,int b) { int c=a+b;
System.out.println(a+\加\等于\ }
void crySpeak(String s) {
System.out.println(m+\ } }
public class Example5_1 {
public static void main(String args[]) { People people=new People();
Anthropoid monkey=people;
monkey.crySpeak(\ System.out.println(monkey.m) ; System.out.println(people.m) ; People zhang=(People)monkey; zhang.computer(55,33); zhang.m='T'; System.out.println(zhang.m) ; } } 答:
A**I love this game**A 12.58 A 55加33等于88 T
5. 请给出下面程序的输出结果 class Circle { double radius; Circle(double r) { radius=r; }
double getArea() {
return 3.14*radius*radius; }
void setRadius(double r) { radius=r; }
double getRadius() { return radius; } }
class Circular { Circle bottom; double height;
Circular(Circle c,double h) { bottom = c; height = h; }
double getVolme() {
return bottom.getArea()*height/3.0; }