试卷编号:25111
所属语言:Java
试卷方案:Java阶段测试二
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:7299 难度:中 第1章
Java语言中,占用32位存储空间的是
A:long,double
B:long,float
C:int,double
D:int,float
答案:D
第2题 (1.0分) 题号:6534 难度:中 第1章
已知x和y均为boolean型变量,则x&&y的值为true的条件是什么?
A:至少其中一个为true
B:至少其中一个为false
C:x和y均为true
D:x和y均为false
答案:C
第3题 (1.0分) 题号:7298 难度:中 第1章
现有一个变量声明为booleanaa;下面赋值语句中正确的是
A:aa=false;
B:aa=False;
C:aa="true";
D:aa=0;
答案:A
第4题 (1.0分) 题号:7303 难度:中 第2章
下列语句序列执行后,m的值是
int m=1;
for(inti=5;i>0;i--)
m*=i;
A:15
B:120
C:60
D:0
答案:B
第5题 (1.0分) 题号:7309 难度:中 第2章
下列语句序列执行后,s的值是
int s=1,i=1;
while(i<=4){
s=s*i;
i++;}
A:6
B:4
C:24
D:5
答案:C
第6题 (1.0分) 题号:7308 难度:中 第2章
下列语句序列执行后,i的值是
int i=10;
do { i/=2; } while( i>1 );
A:1
B:5
C:2
D:0
答案:A
第7题 (1.0分) 题号:7334 难度:中 第3章
下面方法定义中,正确的是:
A:intx(){char ch='a';return (int)ch;}
B:voidx(){return true;}
C:intx(){return true;}
D:int x(inta,b){return a-b;}
答案:A
第8题 (1.0分) 题号:7335 难度:中 第3章
设X,Y是已定义的类名,下列声明X类的对象x1的语句正确的是:
A:static Xx1(123);
B:public Xx1=new X(123);
C:Y x1;
D:X x1=X();
答案:B
第9题 (1.0分) 题号:7322 难度:中 第3章
下列方法定义中,方法头不正确的是?
A:double m(int m){ }
B:void m( intm){ }
C:public intm(int m, int n){ }
D:m( inth,int m,int n){ }
答案:D
第10题 (1.0分) 题号:7338 难度:中 第4章
以下关于构造函数的描述错误的是 ?
A:构造函数的返回类型只能是void型
B:构造函数是类的一种特殊函数,它的方法名必须与类名相同
C:构造函数的主要作用是完成对类的对象的初始化工作
D:一般在创建新对象时,系统会调用构造函数
答案:A
第11题 (1.0分) 题号:7317 难度:中 第5章
有以下方法的定义,请选择该方法的返回类型?
typemethod(byte x,float y){
return x/y*2;
}
A:byte
B:short
C:int
D:float
答案:D
第12题 (1.0分) 题号:7344 难度:中 第6章
下面哪个关键字用来修饰常量()
A:static
B:final
C:public
D:private
答案:B
第13题 (1.0分) 题号:7318 难度:中 第6章
假设A类有如下定义,设a是A类的一个实例,下列语句调用哪个是错误的?
class A{
int i;
static Strings;
voidmethod1(){ }
static voidmethod2(){ }
}
A:System.out.println(a.i);
B:a.method1();
C:A.method1();
D:A.method2();
答案:C
第14题 (1.0分) 题号:7350 难度:中 第7章
下列选项中关于super关键字的说法正确的是()
A:super关键字是在子类对象内部指代其父类对象的引用
B:super关键字不仅可以指代子类的直接父类,还可以指代父类的父类
C:子类通过super关键字只能调用父类的方法,而不能调用父类的属性
D:子类通过super关键字只能调用父类的属性,而不能调用父类的方法
答案:A
第15题 (1.0分) 题号:7351 难度:中 第7章
关于super的说法正确的是( ).
A:是指当前对象的内存地址
B:是指当前对象的父类对象的内存地址
C:是指当前对象的父类
D:可以用在main()方法中
答案:B
第16题 (1.0分) 题号:7355 难度:中 第8章
下面哪个关键字用于将类中的属性私有化()
A:default
B:protected
C:public
D:private
答案:D
第17题 (1.0分) 题号:7356 难度:中 第8章
下面哪两个关键字是类的可见性修饰符()
A:public和默认的
B:public和private
C:private和默认的
D:protected和默认的
答案:A
第18题 (1.0分) 题号:7364 难度:中 第9章
以下关于方法的覆盖的说法,错误的是()
A:子类的方法与父类的方法,方法名必须相同
B:子类的方法与父类的方法,参数形式必须相同
C:子类的方法与父类的方法,返回值类型必须相同
D:以上都不对
答案:D
第19题 (1.0分) 题号:7369 难度:中 第10章
下面说法正确的是().
A:final可修饰类、属性、方法.
B:abstract可修饰类、属性、方法.
C:定义抽象方法需要给出方法的返回值类型、方法名、参数列表和方法体.
D:用final修饰的变量,在程序中可对这个变量的值进行修改.
答案:A
第20题 (1.0分) 题号:7373 难度:中 第11章
下列类头定义中,错误的是 ?
A:public xextends y
B:publicclass x extends y
C:class xextends y implements y1
D:class x
答案:A
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1059 难度:中 第1章
Which are validdeclarations?
A:int $x;
B:int 123;
C:int _123;
D:int%percent;
E:int*divide;
F:intcentral_sales_region_Summer_2005_gross_sales;
答案:ACF
第2题 (2.0分) 题号:1058 难度:中 第1章
what is theresult when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
Strings="Hello"
Select allright answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第3题 (2.0分) 题号:1062 难度:中 第1章
给定下面的类定义
public classShrubHill{
public voidforegate(String sName){}
//Here
}
下面的哪一个方法可以合法的直接替换//Here?
A:public intforegate(String sName){}
B:public voidforegate(StringBuffer sName){}
C:public voidforeGate(String sName){}
D:privatevoid foregate(String sType){}
答案:BC
第4题 (2.0分) 题号:989 难度:中 第2章
classExample{
public static void main(String[] args){
int x
if(x>4){System.out.println("case 1");}
else if(x>9){
System.out.println("case 2");
}
else{System.out.println("case 3");}
}
}
what value ofx will cause case 3 printed in the output
A:less thanzero
B:less 4
C:between 4and 9
D:10 andgreater
E:None
答案:B
第5题 (2.0分) 题号:984 难度:中 第2章
what is theresult when you compile and run the following code?
pubic classExample{
public static void main(String[] args){
int x;
if(x>0){System.out.println("first");}
else if(x>-3){
System.out.println("second");
}
else{System.out.println("third");
}
}
Which rangeof x value would print the string "second"
A:x>0
B:x>-3
C:x<=-3
D:x<=0&x>-3
答案:D
第6题 (2.0分) 题号:991 难度:中 第2章
What is thevalue of j when printed
classExample{
public static void main(String[] args){
long x=4,j=0;
switch(x){
case 1:j++;
case 2:j++;
case 3:j++;
case 4:j++;
case 5:j++;
break;
default: j++;
}
System.out.println(j);
}
}
A:1
B:Compileerror
C:6
D:3
E:2
答案:B
第7题 (2.0分) 题号:925 难度:中 第2章
现有:
1. class Test4 {
2. public static void main (String [] args) {
3. boolean x=true;
4. boolean y=false;
5. short z=42;
7. if((z++==42) && (y==false))z++;
8. if((x==false) || (++z==44)) z++;
10. System. out.println("z="+z);
11. }
12. }
结果为:
A:z=42
B:z=44
C:z= 45
D:z= 46
答案:C
第8题 (2.0分) 题号:995 难度:中 第2章
How can youchange the break statement below so that it breaks out of the inner
and middle loops and continues with the nextiteration of the outer loop?
classExample{
public static void main(String[] args){
outer:for(int x=0;x<3;x++){
middle: for(inty=0;y<3;y++){
inner:for(intz=0;z<3;z++){
break;
}
}
}
}
}
A:breakinner;
B:breakouter;
C:breakmiddle;
D:continue
E:continuemiddle
答案:C
第9题 (2.0分) 题号:968 难度:中 第3章
what is theresult when you compile and run the following code?
classUse{public int i=10;}
class Example
{
public staticvoid main(String [] args)
{
Example o=new Example();
o.amethod();
}
public voidamethod()
{
int i=99;
Use v=new Use();
v.i=30;
another(v, i);
System.out.println(a.i);
}
public voidanother(User v,int i)
{
i=0;
v.i=20;
Use vh=newUse();
v=vh;
System.out.println(v.i+" "+i+" ");
}
Select allright answer?
A:10 0 30
B:10 0 20
C:20 0 30
D:20 99 30
答案:B
第10题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:publicprotected amethod(int i)
B:public voidamethod(int i)
C:public voidamethod(void)
D:void publicamethod(int i)
答案:B
第11题 (2.0分) 题号:976 难度:中 第3章
你如何在类中实现封装?
A:make allvariables protected and only allow access via methods
B:make allvariables private and only allow access via methods
C:ensure allvariables are represented by wrapper classes
D:ensure allvariables are accessed through methods in an ancestor class
答案:B
第12题 (2.0分) 题号:977 难度:中 第3章
what is theresult when you compil and run the following code?
class Example
{
static int myArg=1;
public staticvoid main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select allright answer:
A:this codecompiles and displays 0 in the statndard output when run
B:this codecompiles and displays 1 in the statndard output when run
C:this codedoes not compile because you can't define a local variable names the same asstatic variable
D:this codedoesn't compile because the local vriable is used before it is initialized
答案:D
第13题 (2.0分) 题号:953 难度:中 第4章
Given:
class Top {
publicTop(String s) { System.out.print("B"); }
}
public classBottom2 extends Top {
publicBottom2(String s) { System.out.print("D"); }
public staticvoid main(String [] args) {
newBottom2("C");
System.out.println("");
} }
What is theresult?
A:BD
B:DB
C:BDC
D:DBC
E:Compilationfails
答案:E
第14题 (2.0分) 题号:941 难度:中 第4章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
public finalvoid amethod(){
System.out.println("amethod");
}
}
public classFin extends Base{
public staticvoid main(String argv[]){
Base b = newBase();
b.amethod();
}
}
A:Compiletime error indicating that a class with any final methods must be declaredfinal itself
B:Compiletime error indicating that you cannot inherit from a class with final methods
C:Run timeerror indicating that Base is not defined as final
D:Success incompilation and output of "amethod" at run time.
答案:D
第15题 (2.0分) 题号:955 难度:中 第4章
Given:
1. classPlant {
2. StringgetName() { return "plant"; }
3. PlantgetType() { return this; }
4. }
5. classFlower extends Plant {
6. // insertcode here
7. }
8. classTulip extends Flower { }
Whichstatement(s), inserted at line 6, will compile? (Choose all that apply.)
A:FlowergetType() { return this; }
B:StringgetType() { return "this"; }
C:PlantgetType() { return this; }
D:Tulip getType(){ return new Tulip(); }
答案:ACD
第16题 (2.0分) 题号:945 难度:中 第4章
假设有如下类定义
class Mammal{
Mammal () {
System.out.println("Mamml");
}
}
class Dogextends Mammal {
Dog () {
System.out.println("Dog");
}
}
public classCollie extends Dog {
public staticvoid main (String argv []) {
Collie c =new Collie ();
}
Collie () {
this("Good Dog");
System.out.println("Collie");
}
Collie(String s) {
System.out.println(s);
}
}
将会输出什么?
A:Compiletime error
B:Mammal,Dog, Good Dog, Collie
C:Good Dog,Collie, Dog, Mammal
D:Good Dog,Collie
答案:B
第17题 (2.0分) 题号:961 难度:中 第4章
Given thefollowing,
1. class X {void do1() { } }
2. class Yextends X { void do2() { } }
3.
4. classChrome {
5. publicstatic void main(String [] args) {
6. X x1 = newX();
7. X x2 = newY();
8. Y y1 = newY();
9. // insertcode here
10. }
11. }
Which,inserted at line 9, will compile?
A:x2.do2();
B:(Y)x2.do2();
C:((Y)x2).do2();
D:None of theabove statements will compile.
答案:C
第18题 (2.0分) 题号:938 难度:中 第5章
Which istrue? (Choose all that apply.)
A:"Xextends Y" is correct if and only if X is a class and Y is an interface.
B:"Xextends Y" is correct if and only if X is an interface and Y is a class.
C:"Xextends Y" is correct if X and Y are either both classes or bothinterfaces.
D:"Xextends Y" is correct for all combinations of X and Y being classes and/orinterfaces.
答案:C
第19题 (2.0分) 题号:936 难度:中 第5章
Given thefollowing,
1. interfaceBase {
2. boolean m1();
3. bytem2(short s);
4. }
Which codefragments will compile? (Choose all that apply.)
A:interfaceBase2 implements Base { }
B:abstractclass Class2 extends Base {
publicboolean m1() { return true; } }
C:abstractclass Class2 implements Base { }
D:abstractclass Class2 implements Base {
publicboolean m1() { return (true); } }
E:classClass2 implements Base {
boolean m1(){ return false; }
byte m2(shorts) { return 42; } }
答案:CD
第20题 (2.0分) 题号:964 难度:中 第5章
Select thetwo statements that best indicate a situation with low coupling.
A:Theattributes of the class are all private.
B:The classrefers to a small number of other objects.
C:The objectcontains only a small number of variables.
D:The objectis referred to using an anonymous variable, not directly.
E:Thereference variable is declared for an interface type, not a class. Theinterface provides a small number of methods.
F:It isunlikely that changes made to one class will require any changes in another.
答案:EF
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:930 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:设计一个描述二维平面上点的类Point,要求如下:
(a)该类需要描述点的浮点型的横坐标x和纵坐标y。
(b)提供能够初始化横纵坐标的有参构造方法,要求参数名称与属性同名。
(c)计算两点间距离的方法distance。
提示:两点之间距离等于两点横纵坐标之差的平方和再开方
Math类中求平方根的方法:static double sqrt(double a)
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Point p1=new Point(2,3);
Point p2=new Point(4,5);
System.out.println("两个点的距离:"+p1.distance(p2));
}
}
答案:classPoint {
double x;
double y;
public Point(double x,double y){
this.x=x;
this.y=y;
}
public double distance(Point p){
return Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
}
第2题 (10.0分) 题号:928 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个电风扇类Fan,要求如下:
(a)属性包括:电风扇型号model(String类型)、价格price(double类型)
和开关状态running(boolean类型),并且所有属性为私有。
(b)至少提供一个有参的构造方法(要求型号可以初始化为任意值,价格不能小于0,
开关状态必须为false)。
(c)为私有属性提供访问器方法。
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Fan m1=new Fan("吊扇",300);
}
}
答案:classFan {
private String model;
private double price;
private boolean running;
public Fan(String model,double price){
this.model=model;
if(price>=0)
this.price=price;
this.running=false;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public boolean isRunning() {
return running;
}
public void setRunning(boolean running) {
this.running = running;
}
public String getModel() {
return model;
}
}
第3题 (10.0分) 题号:846 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Apple,子类定义了自己的属性String 类型的类别(kind),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Apple类的编写。
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Appleextends Goods {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
答案:Stringkind;
Apple(doubleunitPrice, double account, String kind) {
super(unitPrice,account);
this.kind= kind;
}
doubletotalPrice() {
returnunitPrice * account;
}
voidshow() {
System.out.println("苹果的类别是" + kind);
super.show();
}
第4题 (10.0分) 题号:903 难度:中 第21章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:声明一个抽象类Car,该类有颜色color(String类型)
和汽车速度speed(double类型)两个私有属性,有带一个参数的构造
方法,能够利用参数初始化颜色Color。有两个私有属性的访问器方法。
还有一个抽象的startup方法,该方法无返回值无参。
再声明一个Car的子类Benz。该类覆盖startup方法,输出“benz startup”
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Car c1 = new Benz("black");
}
}
答案:abstractclass Car
{
private String color;
private double speed;
public Car(String color){
this.color = color;
}
public void setColor(String color)
{
this.color = color;
}
public String getColor(){
return color;
}
public void setSpeed(double speed){
this.speed = speed;
}
public double getSpeed(){
return speed;
}
abstract void startup();
}
classBenz extends Car{
public Benz(String color){
super(color);
}
public void startup(){
System.out.println("benzstartup");
}
}
、试卷编号:25112
所属语言:Java
试卷方案:Java阶段测试二
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:6543 难度:中 第1章
下列单词中,不属于Java关键字的是
A:NULL
B:class
C:this
D:byte
答案:A
第2题 (1.0分) 题号:6542 难度:中 第1章
下面哪个标识符是合法的
A:#_pound
B:$123+w
C:5Interstate
D:a_b
答案:D
第3题 (1.0分) 题号:6539 难度:中 第1章
定义变量int i=3;那么表达式i/6 * 5的计算结果是
A:0
B:1
C:2.5
D:2
答案:A
第4题 (1.0分) 题号:7305 难度:中 第2章
下列对Java语言的叙述中,错误的是
A:Java虚拟机解释执行字节码
B:Java中执行跳转功能的语句是switch语句
C:Java的类是对具有相同行为对象的一种抽象
D:Java中的垃圾回收机制是一个系统级的线程
答案:B
第5题 (1.0分) 题号:7313 难度:中 第2章
下列语句序列执行后,x 的值是
inta=4,b=1,x=6;
if(a==b)x+=a;
else x=++a*x;
A:15
B:30
C:25
D:5
答案:B
第6题 (1.0分) 题号:7304 难度:中 第2章
Java 支持的3 种跳转语句不包括
A:break语句
B:continue语句
C:return语句
D:goto语句
答案:D
第7题 (1.0分) 题号:7326 难度:中 第3章
下面关于类的结构的说法正确的是 ?
A:类只能包含一个构造方法
B:类可以没有属性
C:类只能包含方法
D:类只能包含属性
答案:B
第8题 (1.0分) 题号:7330 难度:中 第3章
下面正确的main方法是
A:publicstatic void main(String args)
B:publicstatic int main(String[] args)
C:public staticvoid main(String[] args)
D:publicfinal void main(String args)
答案:C
第9题 (1.0分) 题号:7325 难度:中 第3章
下面类的定义中结构正确的是?
A:class A
B:class 2A
C:int class A
D:public class A ()
答案:A
第10题 (1.0分) 题号:7339 难度:中 第4章
下列构造方法的调用方式中,正确的是
A:按照一般方法调用
B:由用户直接调用
C:只能通过new自动调用
D:不用调用,自动执行
答案:C
第11题 (1.0分) 题号:7362 难度:中 第5章
在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或顺序各不相同,返回的值也可以不相同.这种面向对象程序特性称为?
A:隐藏
B:覆盖
C:重载
D:Java不支持此特性
答案:C
第12题 (1.0分) 题号:7342 难度:中 第6章
下列关于静态方法的描述中,错误的是
A:静态方法属于类的共享成员
B:静态方法是通过"类名.方法名"的方式来调用
C:静态方法只能被类调用,不能被对象调用
D:静态方法中可以访问静态变量
答案:C
第13题 (1.0分) 题号:7345 难度:中 第6章
下面关于常量的描述,正确的是()
A:常量在主函数中可以被修改
B:常量在主函数中不可以被修改
C:常量一般用static来定义
D:常量一定会被调用
答案:B
第14题 (1.0分) 题号:7349 难度:中 第7章
父子类在同一个包中,子类不能继承父类的哪个属性()
A:default
B:protected
C:public
D:private
答案:D
第15题 (1.0分) 题号:7348 难度:中 第7章
继承的关键字是()
A:extend
B:extends
C:Extend
D:Extends
答案:B
第16题 (1.0分) 题号:7358 难度:中 第8章
下面关于方法的修饰符,哪个只能在当前类中使用()
A:default
B:protected
C:public
D:private
答案:D
第17题 (1.0分) 题号:7361 难度:中 第8章
关于类的继承的描述,正确的是()
A:一个类可以继承多个父类
B:一个类可以具有多个子类
C:子类可以使用父类的所有方法
D:子类必须覆盖父类的全部方法
答案:B
第18题 (1.0分) 题号:7366 难度:中 第9章
下面关于多态性的说法,正确的是()
A:一个类中不能有同名的方法
B:子类中不能有和父类中同名的方法
C:子类中可以有和父类中同名且参数相同的方法
D:多态性就是方法的名字可以一样,但返回的类型必须不一样
答案:C
第19题 (1.0分) 题号:7367 难度:中 第10章
定义抽象类的关键字是()
A:abstractclass
B:final class
C:staticclass
D:publicclass
答案:A
第20题 (1.0分) 题号:7372 难度:中 第11章
在使用interface声明一个接口时,只可以使用哪个修饰符修饰该接口.
A:private
B:protected
C:private或者protected
D:public
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:920 难度:中 第1章
下列哪项不是有效的标识符?
A:userName
B:2test
C:$change
D:_password
E:class
答案:BE
第2题 (2.0分) 题号:923 难度:中 第1章
现有:
class Test2 {
public static void main (String [] args) {
short a,b,c;
a=1;
b=2;
c=a+b;
a+=2;
}
}
以上代码中,哪一句是错误的?
A:a=1;
B:c=a+b;
C:a+=2;
D:shorta,b,c;
答案:B
第3题 (2.0分) 题号:921 难度:中 第1章
下列哪项是Java语言中所规定的注释样式?
A://单行注释
B:--单行注释
C:/*
*单行或多行注释
*/
D:/**
*文档注释
*/
答案:ACD
第4题 (2.0分) 题号:992 难度:中 第2章
what is theresult when you compile and run the following code
classExample{
public static void main(String[] args){
int i=1
switch(i){
case 0:System.out.println("zero");break;
case1:System.out.println("one");
case2:System.out.println("two");
default:System.out.println("default");
}
}
}
A:one
B:one,default
C:one,two,default
D:default
答案:C
第5题 (2.0分) 题号:994 难度:中 第2章
classExample{
public static void main(String[] args){
int t=0;
while(1)
{ if(t++<10) break;
}
}
}
what will bethe value of t after the while loop?
A:9
B:10
C:11
D:CompilationError
E:AnException will occurs
答案:D
第6题 (2.0分) 题号:1005 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
int i=0;j=5;
st:for( ; ; i++){
for( ; ; j--){
if(i>j) { break st;}
}
}
System.out.println("i="+i+"j="+j);
}
}
A:i=0 j=-1
B:i=1 j=0
C:i=0 j=1
D:i=1 j=-1
E:Compileerror at line 4
答案:A
第7题 (2.0分) 题号:932 难度:中 第2章
现有:
1. class Test2 f
2. public static void main (String [] args) {
3. boolean x= true;
4. boolean y=false;
5. short z=20;
6.
7. if((x==true) && (y==true)) z++;
8. if((y==true) || (++z==22)) z++;
9.
10. System. out .println( "z="+z);
11. }
12. }
结果是什么?
A:z=21
B:z=22
C:z=23
D:z= 24
答案:A
第8题 (2.0分) 题号:933 难度:中 第2章
现有:
1. class Foo {
2. public static void main (String [] args) {
3. int x=0;
4. int y=4;
5. for (int z=0; z<3; z++) {
6. if(x>1&++y<10)
7. y++;
x++;
8. }
9. System. out .println (y);
10. }
11. }
结果是什么?
A:7
B:8
C:10
D:12
E:13
答案:B
第9题 (2.0分) 题号:971 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{ String s;
public static void main(String []args)
{ Example ks=new Example();
int j,i;
i=ks.hai();
j=ks.hello();
System.out.println(i+""+j);
}
int hai()
{
if((s==null)||(s.length()==0)){return 10;}
else return 0;
}
int hello()
{
if((s==null)|(s.length()==20)){return 10;}
else return 0;
}
}
Select allright answer:
A:10 10
B:10 null
C:0 0
D:compilationerror
E:Anexception in hai
F:an exceptonin hello
答案:F
第10题 (2.0分) 题号:974 难度:中 第3章
当你试着编译运行下面的两个放在同一个目录的文件的时候,可能会发生什么?
//FileP1.java
packageMyPackage;
class P1{
voidafancymethod(){
System.out.println("Whata fancy method");
}
}
//FileP2.java
public classP2 extends P1{
afancymethod();
}
A:Bothcompile and P2 outputs "What a fancy method" when run
B:Neitherwill compile
C:Bothcompile but P2 has an error at run time
D:P1 compilescleanly but P2 has an error at compile time
答案:D
第11题 (2.0分) 题号:972 难度:中 第3章
给定下面的类
public classCrowle{
public staticvoid main(String argv[]){
Crowle c =new Crowle();
}
Crowle(){
System.out.println("Greetingsfrom Crowle");
}
}
构造方法会返回哪一种数据类型?
A:null
B:integer
C:String
D:no datatypeis returned
答案:D
第12题 (2.0分) 题号:965 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
int x=12;
publicvoid method(int x)
{
x+=x;
System.out.println(x);
}
public staticvoid main(String [] args)
{
Example t=new Exaple();
t.method(5);
}
}
What is theoutput from the example class?
Select allright answer?
A:5
B:10
C:12
D:17
E:24
答案:B
第13题 (2.0分) 题号:949 难度:中 第4章
给定下面的类定义
class Base{
public voidamethod(){
System.out.println("Base");
}
}
public classHay extends Base{
public staticvoid main(String argv[]){
Hay h = newHay();
h.amethod();
}
}
下面在类Hay 中的哪一个方法将会编译并使程序打印出字符串"Hay"?
A:public intamethod(){ System.out.println("Hay");}
B:public voidamethod(long l){ System.out.println("Hay");}
C:public voidamethod(){ System.out.println("Hay");}
D:public voidamethod(void){ System.out.println("Hay");}
答案:C
第14题 (2.0分) 题号:958 难度:中 第4章
Given:
class Uber {
static int y= 2;
Uber(int x) {this(); y = y * 2; }
Uber() { y++;}
}
class Minorextends Uber {
Minor() {super(y); y = y + 3; }
public staticvoid main(String [] args) {
new Minor();
System.out.println(y);
} }
What is theresult?
A:6
B:7
C:8
D:9
E:Compilationfails.
F:Anexception is thrown.
答案:D
第15题 (2.0分) 题号:943 难度:中 第4章
下面的哪一句陈述是正确的?
A:The defaultconstructor has a return type of void
B:The defaultconstructor takes a parameter of void
C:The defaultconstructor takes no parameters
D:The defaultconstructor is not created if the class has any constructors of its own.
答案:CD
第16题 (2.0分) 题号:952 难度:中 第4章
Given:
classClidders {
public finalvoid flipper() { System.out.println("Clidder"); }
}
public classClidlets extends Clidders {
public voidflipper() {
System.out.println("Flipa Clidlet");
super.flipper();
}
public staticvoid main(String [] args) {
newClidlets().flipper();
}
}
What is theresult?
A:Flip aClidlet
B:Flip aClidder
C:Flip aClidder
Flip a Clidlet
D:Flip aClidlet
Flip aClidder
E:Compilationfails.
答案:E
第17题 (2.0分) 题号:950 难度:中 第4章
假设你被给予如下设计
"一个人有姓名,年龄,地址和性别。你将要设计一个类来表示一类叫做病人的人。这种人
可以被给予诊断,有配偶并且可能活着"。假设表示人的类已经创建了,当你设计病人类时
如下哪些应该被包含在内?
A:registrationdate
B:age
C:sex
D:diagnosis
答案:AD
第18题 (2.0分) 题号:449 难度:中 第5章
关于接口的说法中正确的是
A:接口所有的方法都是抽象的
B:接口所有的方法一定都是public属性的
C:用于定义接口的关键字是implements
D:接口是Java中特殊类,包含常量和抽象方法
答案:ABD
第19题 (2.0分) 题号:937 难度:中 第5章
Which declarea compilable abstract class? (Choose all that apply.)
A:publicabstract class Canine { public Bark speak(); }
B:publicabstract class Canine { public Bark speak() { } }
C:publicclass Canine { public abstract Bark speak(); }
D:publicclass Canine abstract { public abstract Bark speak(); }
答案:B
第20题 (2.0分) 题号:939 难度:中 第5章
publicabstract interface Frobnicate { public void twiddle(String s); }
Which is acorrect class? (Choose all that apply.)
A:publicabstract class Frob implements Frobnicate {
publicabstract void twiddle(String s) { }
}
B:publicabstract class Frob implements Frobnicate { }
C:publicclass Frob extends Frobnicate {
public voidtwiddle(Integer i) { }
}
D:publicclass Frob implements Frobnicate {
public voidtwiddle(Integer i) { }
}
E:publicclass Frob implements Frobnicate {
public voidtwiddle(String i) { }
public voidtwiddle(Integer s) { }
}
答案:B
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:933 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:设计一个汽车类Vehicle,要求如下:
(a)属性有车轮个数wheels(int类型)和车重weight(double类型)。
(b)构造方法包括:带参数的构造方法,能够初始化车轮个数和车重
(c)方法包括:输出所有属性的printInfo方法
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Vehicle v=new Vehicle(3,5.0);
}
}
答案:classVehicle {
int wheels;
double weight;
public Vehicle(int wheels,double weight){
this.wheels=wheels;
this.weight=weight;
}
public void printInfo(){
System.out.println("车轮数:"+wheels);
System.out.println("车载重:"+weight);
}
}
第2题 (10.0分) 题号:932 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:设计一个关于等边三角形的类Trival,要求如下:
(a)属性包括三角形的边side(double类型)
(b)构造方法包括:无参构造方法和为side指定初值的有参构造方法
(c)方法包括:获取三角形面积findArea()。
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Trival t=new Trival(3.0);
}
}
答案:classTrival{
double side;
public Trival(double side){
this.side=side;
}
public Trival(){
this.side=1;
}
public double findArea(){
return Math.sqrt(3)*side*side/4;
}
}
第3题 (10.0分) 题号:843 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Person,在此基础上派生出子类Teacher,子类定义了自己的属性String类型的教师编号(teacherID),
有不带参数的构造方法,覆盖了父类的print方法,调用父类被覆盖的print方法,增加打印自己的属性的语句,
请实现Teacher类的编写。
-------------------------------------------------------*/
class Person{
String id;
String name;
Person(String id, String name) {
this.id = id;
this.name = name;
}
void print() {
System.out.println("id=" + id + ",name =" + name);
}
}
class Teacherextends Person {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args) {
}
}
答案:StringteacherID;
Teacher(){
super("2201212","rose");
teacherID= "10010101";
}
voidprint() {
super.print();
System.out.println("teacherID=" + teacherID);
}
第4题 (10.0分) 题号:905 难度:中 第21章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:按要求将下面程序补充完整:
已有接口CanFly和CanJump,分别描述飞和跳的能力。要求:
声明Locust(蝗虫)类和Balloon(气球)类,Locust类具有飞和跳
的能力,Balloon类具有飞的能力。飞和跳的方法可以通过输出相应
的字符串来实现。
然后,在主类Prog1中,添加一个静态的方法testFly(),其功能是
让能飞的物体执行飞的动作。在main方法中分别创建Locust类和
Balloon类的对象,调用testFly()方法。
-------------------------------------------------------*/
interfaceCanFly {
public void fly();
}
interfaceCanJump {
public void jump();
}
/**********Program**********/
public classProg1{
public static void main(String[] args){
testFly(new Locust());
testFly(new Balloon());
}
}
/********** End **********/
答案:classLocust implements CanFly,CanJump{
public void jump() {
System.out.println("locust isjumping");
}
public void fly() {
System.out.println("locust isflying");
}
}
classBalloon implements CanFly{
public void fly(){
System.out.println("balloon isflying");
}
}
publicclass Prog1{
static void testFly(CanFly c){
c.fly();
}
public static void main(String[] args){
testFly(new Locust());
testFly(new Balloon());
}
}
试卷编号:25113
所属语言:Java
试卷方案:Java阶段测试二
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:6541 难度:中 第1章
下列哪一个是合法的标识符
A:12class
B:+viod
C:-5
D:_black
答案:D
第2题 (1.0分) 题号:7296 难度:中 第1章
以下的选项中能正确表示Java语言中的一个整型常量的是
A:12.
B:-20
C:1,000
D:4 5 6
答案:B
第3题 (1.0分) 题号:6536 难度:中 第1章
对于一个三位的正整数 n,取出它的十位数字k(k为整型)的表达式是
A:k = n / 10% 10
B:k = n%10 %10
C:k = n % 10
D:k = n / 10
答案:A
第4题 (1.0分) 题号:7311 难度:中 第2章
下列语句序列执行后,k 的值是
inti=4,j=5,k=9,m=5;
if(i>j||m<k)k++;
else k--;
A:5
B:9
C:8
D:10
答案:D
第5题 (1.0分) 题号:7312 难度:中 第2章
有以下代码,运行完后i的最终值是
int i=1;
int j=i++;
if((i>++j)&&(i++==j)) i+=j;
A:1
B:2
C:3
D:4
答案:B
第6题 (1.0分) 题号:7315 难度:中 第2章
以下for循环的执行次数是:
for(intx=0;(x==0)&(x>4);x++);
A:无限次
B:一次也不执行
C:4次
D:3次
答案:B
第7题 (1.0分) 题号:7385 难度:中 第3章
关于java源文件下列说法正确的是?
A:一个java源文件中只能有一个public修饰的类
B:一个java源文件中只能有一个缺省的类
C:一个java源文件中可以有多个protected修饰的类
D:一个java源文件中可以有多个private修饰的类
答案:A
第8题 (1.0分) 题号:7320 难度:中 第3章
定义类头时,不可能用到的关键字是?
A:class
B:public
C:extends
D:static
答案:D
第9题 (1.0分) 题号:7332 难度:中 第3章
下面方法定义中,正确的是:
A:int x(inta,b){return a-b;}
B:doublex(int a,int b){int w;w=a-b;}
C:doublex(a,b){return b;}
D:int x(inta,int b){return a-b;}
答案:D
第10题 (1.0分) 题号:7337 难度:中 第4章
下列对构造方法的调用方式的描述中正确的是?
A:使用new调用
B:使用类名调用
C:使用对象名调用
D:调用方法为对象名.方法名()
答案:A
第11题 (1.0分) 题号:7363 难度:中 第5章
方法的重载是指,两个方法具有相同名称和不同的参数形式.其中不同的参数形式是指()
A:参数个数和类型不同
B:参数有无返回值
C:方法的修饰符不同
D:以上都不对
答案:A
第12题 (1.0分) 题号:7341 难度:中 第6章
下列关于静态方法的描述中,错误的是
A:静态方法指的是被static关键字修饰的方法
B:静态方法不占用对象的内存空间,而非静态方法占有对象的内容空间
C:静态方法内可以使用this关键字
D:静态方法内部只能访问被static修饰的成员
答案:C
第13题 (1.0分) 题号:7319 难度:中 第6章
为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式可能为?
A:static voidmethod( )
B:public voidmethod( )
C:final voidmethod( )
D:abstractvoid method( )
答案:A
第14题 (1.0分) 题号:7352 难度:中 第7章
父子类不在同一个包中,子类能继承父类的哪个属性()
A:default
B:protected
C:static
D:private
答案:B
第15题 (1.0分) 题号:7347 难度:中 第7章
下面关于super的说法,错误的是()
A:使用super,可以调用父类的构造方法
B:使用super,可以调用父类的属性
C:使用super,可以调用父类的方法
D:使用super,可以调用对象自己的属性和方法
答案:D
第16题 (1.0分) 题号:7354 难度:中 第8章
被声明为private,protected及public的类成员,在类的外部则()
A:不同包中只能访问到声明为public的成员和有父子类关系的protected的成员
B:只能访问到声明为public和protected的成员
C:都可以访问
D:都不能访问
答案:A
第17题 (1.0分) 题号:7359 难度:中 第8章
下面关于get和set方法的叙述,正确的是()
A:两个方法一般都有返回值
B:两个方法一般都没有返回值
C:get方法一般有返回值
D:set方法一般有返回值
答案:C
第18题 (1.0分) 题号:7365 难度:中 第9章
覆盖与重载的关系是:( )
A:覆盖只有发生在父类与子类之间,而重载可以发生在同一个类中
B:覆盖方法可以不同名,而重载方法必须同名
C:final修饰的方法可以被覆盖,但不能被重载
D:覆盖与重载是同一回事
答案:A
第19题 (1.0分) 题号:7368 难度:中 第10章
下面关于抽象类的描述,错误的是()
A:抽象类的修饰符可以是public
B:抽象类的修饰符可以是默认的
C:抽象类中可以有抽象方法,也可以有非抽象方法
D:抽象类中可以有抽象方法,但不可以有非抽象方法
答案:D
第20题 (1.0分) 题号:7371 难度:中 第11章
定义一个接口时,下列哪个关键字用不到?
A:public
B:extends
C:interface
D:class
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1064 难度:中 第1章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{ byte B=10;
byte D=12;
byte I=B*D;
}
}
Select allright answer:
A:the codewill compile and run
B:compiletime error while declaring variable
C:compiletime error while multiplication
D:none of theabove
答案:C
第2题 (2.0分) 题号:445 难度:中 第1章
下列哪些是Java语言中的保留字
A:if
B:sizeof
C:private
D:null
答案:ACD
第3题 (2.0分) 题号:1063 难度:中 第1章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{ int i=012;
int j=034;
int k=056;
int l=078
System.out.println(i);
System.out.println(j);
System.out.println(k);
}
}
Select allright answer:
A:prints 12,34 and 56
B:prints 24,68and 112
C:prints 10,28and 46
D:compilationerror
答案:D
第4题 (2.0分) 题号:996 难度:中 第2章
classExample{
public static void main(String[] args){
int x=0;
// insert code here
do {}
while(x++<y);
System.out.println(x);
}
}
Which,inserted at line 4,produces the output 12?
A:int y=x;
B:int y=10;
C:int y=11;
D:int y=12;
E:int y=13;
F:None of theabove will allow compilation to succeed
答案:C
第5题 (2.0分) 题号:927 难度:中 第2章
class TestApp{
public static void main (String[] args){
int x=6;
if (x>1)
System. out. println("x>1");
else if (x>5)
System. out .println("x>5");
else if (x<10)
System. out. println("x<10");
else if (x<29)
System. out .println( "x<29");
else
System. out.println("以上都不是");
}
}
上述程序运行后的结果是哪项?
A:x>5
B:x>1
C:x<10
D:x<29
答案:B
第6题 (2.0分) 题号:993 难度:中 第2章
What is theresult when you compile and run the following code?
public classExample {
public staticvoid main(String args[]){
byte x;
if(x > 4) {System.out.println("Test 1");}
else if(x>9) {System.out.println( "Test 2");}
else{System.out.println( "Test 3" ); }
}
}
Which rangeof value x would produce of output "Test 2"?
select allright answer:
A:x < 4
B:x > 4
C:x > 9
D:None
答案:D
第7题 (2.0分) 题号:990 难度:中 第2章
what is the resultwhen you compile and run the following code
class Example{
public static void main(String[] args){
int i=3;
int j=0;
double k=3.2;
if(i<k){
if(i==j){System.out.println(i);}
else{System.out.println(j);}
}
else
{System.out.println(k);}
}
}
A:3
B:0
C:3.2
D:none ofthese
答案:B
第8题 (2.0分) 题号:447 难度:中 第2章
下列哪些属于Java语言的流程控制语句
A:赋值语句
B:分支语句
C:跳转语句
D:循环语句
答案:BCD
第9题 (2.0分) 题号:978 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
static int i;
public staticvoid main(String [] args)
{
System.out.println(i);
}
}
Select allright answer:
A:0
B:1
C:null
D:Errorvariable I may not have been initialized
答案:A
第10题 (2.0分) 题号:981 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
int i=20;
static {int i=10;}
public staticvoid main(String [] args)
{
Example a=new Example();
System.out.println(a.i);
}
}
Select allright answer?
A:prints 10
B:prints 20
C:compilation, variable "i" declared twice
D:compilationerror, static initializers for initialization purpose only
答案:B
第11题 (2.0分) 题号:973 难度:中 第3章
当你试着编译运行下面的代码的时候,可能会发生什么?
public classCrowle{
public staticvoid main(String argv[]){
Crowle c =new Crowle();
}
voidCrowle(){
System.out.println("Greetingsfrom Crowle");
}
}
A:Compilationand output of the string "Greetings from Crowle"
B:Compiletime error, constructors may not have a return type
C:Compilationand output of string "void"
D:Compilationand no output at runtime
答案:D
第12题 (2.0分) 题号:979 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
staticboolean Paddy;
public staticvoid main(String [] args)
{
System.out.println(Paddy);
}
}
Select allright answer:
A:compiletime error;
B:compilationand output of false;
C:compilationand output of true
D:compilationand output of null
答案:B
第13题 (2.0分) 题号:947 难度:中 第4章
试图编译并运行下面代码会发生什么?
class Base {
public voidamethod (int i, String s) {
System.out.println("Base amethod");
}
Base () {
System.out.println("Base Constructor");
}
}
public classChild extends Base {
int i;
String Parm ="Hello";
public staticvoid main (String argv []) {
Child c = newChild ():
c.amethod ():
}
void amethod(int i, String Parm) {
super.amethod(i, Parm);
}
public voidamethod () {}
}
A:Compiletime error
B:Errorcaused by illegal syntax super.amethod (i, Parm)
C:Output of"Base Constructor"
D:Errorcaused by incorrect parameter names in call to super.amethod
答案:A
第14题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog{ }
2. classBeagle extends Dog { }
3.
4. classKennel {
5. publicstatic void main(String [] arfs) {
6. Beagle b1= new Beagle();
7. Dog dog1 =new Dog();
8. Dog dog2 =b1;
9. // insertcode here
10. }
11. }
Which,inserted at line 9, will compile?
A:Beagle b2 =(Beagle) dog1;
B:Beagle b3 =(Beagle) dog2;
C:Beagle b4 =dog2;
D:None of theabove statements will compile
答案:AB
第15题 (2.0分) 题号:940 难度:中 第4章
给定下面的类定义
class Base{
Base(int i){}
}
class DefConextends Base{
DefCon(inti){
//XX
}
}
如果将标记//XX 的地方替换为下面的行,哪一行是独立合法的?
A:super();
B:this();
C:this(99);
D:super(99);
答案:D
第16题 (2.0分) 题号:963 难度:中 第4章
Given:
class Fizz {
int x = 5;
public staticvoid main(String[] args) {
final Fizz f1= new Fizz();
Fizz f2 = newFizz();
Fizz f3 =FizzSwitch(f1,f2);
System.out.println((f1== f3) + " " + (f1.x == f3.x));
}
static FizzFizzSwitch(Fizz x, Fizz y) {
final Fizz z= x;
z.x = 6;
return z;
} }
What is theresult?
A:true true
B:true false
C:false true
D:false false
E:Compilationfails.
F:Anexception is thrown at runtime.
答案:A
第17题 (2.0分) 题号:946 难度:中 第4章
下面哪些论述是正确的?
A:Constructorsare not inherited
B:Constructorscan be overridden
C:A parentalconstructor can be invoked using this
D:Any methodmay contain a call to this or super
答案:A
第18题 (2.0分) 题号:443 难度:中 第5章
下列哪些属于Java的数据类型
A:接口
B:无符号整数类型
C:整数类型
D:浮点数类型
答案:ACD
第19题 (2.0分) 题号:935 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
abstractpublic void myfunc();
public voidanother(){
System.out.println("Anothermethod");
}
}
public classAbs extends Base{
public staticvoid main(String argv[]){
Abs a = newAbs();
a.amethod();
}
public voidmyfunc(){
System.out.println("Myfunc");
}
public voidamethod(){
myfunc();
}
}
A:The codewill compile and run, printing out the words "My Func"
B:Thecompiler will complain that the Base class is not declared as abstract.
C:The codewill compile but complain at run time that the Base class has non abstractmethods
D:Thecompiler will complain that the method myfunc in the base class has no body,nobody at all to love it
答案:B
第20题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstractclass Base{
abstractpublic void myfunc();
public voidanother(){
System.out.println("Anothermethod");
}
}
public classAbs extends Base{
public staticvoid main(String argv[]){
Abs a = newAbs();
a.amethod();
}
public voidmyfunc(){
System.out.println("Myfunc");
}
public voidamethod(){
myfunc();
}
}
A:The codewill compile and run, printing out the words "My Func"
B:Thecompiler will complain that the Base class has non abstract methods
C:The codewill compile but complain at run time that the Base class has non abstractmethods
D:Thecompiler will complain that the method myfunc in the base class has no body,nobody at all to love it
答案:A
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:842 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义类,属性包括商品名称name(String)、商品编号id(String)和价格price(double)三个属性,
有无参的构造方法和计算折扣价格并输出的方法,方法头为public void computeDiscout(double percent),
其中形参代表打折的百分比。
创建商品类的对象,调用计算折扣价格的方法。
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:Stringname;
Stringid;
doubleprice;
Prog1(){
name="虾条"; id="g009";
price=3.5;
}
publicvoid computeDiscout(double percent) {
System.out.println(name+ "原价为" + price+"元");
price= price * percent;
System.out.println(name+ "折扣后的价格是" + price+"元");
}
publicstatic void main (String[] args) {
Prog1g=new Prog1();
g.computeDiscout(0.9);
}
第2题 (10.0分) 题号:928 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个电风扇类Fan,要求如下:
(a)属性包括:电风扇型号model(String类型)、价格price(double类型)
和开关状态running(boolean类型),并且所有属性为私有。
(b)至少提供一个有参的构造方法(要求型号可以初始化为任意值,价格不能小于0,
开关状态必须为false)。
(c)为私有属性提供访问器方法。
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Fan m1=new Fan("吊扇",300);
}
}
答案:classFan {
private String model;
private double price;
private boolean running;
public Fan(String model,double price){
this.model=model;
if(price>=0)
this.price=price;
this.running=false;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public boolean isRunning() {
return running;
}
public void setRunning(boolean running) {
this.running = running;
}
public String getModel() {
return model;
}
}
第3题 (10.0分) 题号:845 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Milk,子类定义了自己的属性double类型的会员价格(vipPrice),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Milk类的编写
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Milkextends Goods {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
答案:doublevipPrice;
Milk(doublen, double p, double vipPrice) {
super(n,p);
this.vipPrice= vipPrice;
}
voidshow() {
super.show();
System.out.println("会员价格是" + vipPrice);
}
第4题 (10.0分) 题号:904 难度:中 第21章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:声明一个抽象类User,该类有用户名name(String类型)
和密码pass(String类型)两个私有属性,有带参数的构造方法,
能够利用参数初始化name和pass。有两个私有属性的访问器方法。
还有一个抽象的login方法,该方法无返回值无参。
再声明一个User的子类Admin。该类覆盖login方法,输出“adminlogin”
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
User u1 = new Admin("admin","11");
}
}
答案:abstractclass User
{
private String name;
private String pass;
public User(String name,String pass){
this.name = name;
this.pass = pass;
}
public void setName(String name)
{
this.color = color;
}
public String getName(){
return name;
}
public void setPass(String pass){
this.pass = pass;
}
public double getPass(){
return pass;
}
abstract void login();
}
classAdmin extends User{
public Admin(String name,String pass){
super(name,pass);
}
public void login(){
System.out.println("adminlogin");
}
}
试卷编号:25114
所属语言:Java
试卷方案:Java阶段测试二
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:7297 难度:中 第1章
下列数据类型的精度由高到低的顺序是
A:float,double,int,long
B:double,float,int,byte
C:byte,long,double,float
D:double,int,float,long
答案:B
第2题 (1.0分) 题号:6535 难度:中 第1章
设有定义floatx=3.5f, y=4.6f, z=5.7f; 则以下的表达式中,值为true的是
A:x > y ︱︱ x > z
B:x != y
C:z > ( y+ x )
D:y>z
答案:B
第3题 (1.0分) 题号:6538 难度:中 第1章
关于数据类型转换的说法那个是不正确的
A:Java共有两种数据类型的转换方式:自动转换和强制转换
B:Java中当两个类型不同的运算对象进行二元运算时,Java自动把精度较低的类型转换成另一个精度较高的类型
C:boolean型数据能和其他数据类型进行转换
D:char型和int型数据可以互相转换
答案:C
第4题 (1.0分) 题号:7306 难度:中 第2章
下列语句中执行跳转功能的语句是
A:for语句
B:while语句
C:continue语句
D:switch语句
答案:C
第5题 (1.0分) 题号:7307 难度:中 第2章
在switch(expression)语句中,expression的数据类型不能是
A:byte
B:char
C:float
D:short
答案:C
第6题 (1.0分) 题号:7316 难度:中 第2章
以下for循环的执行次数是:
for(intx=0;(x==0)&(x<4);x++);
A:无限次
B:1次
C:4次
D:3次
答案:B
第7题 (1.0分) 题号:7331 难度:中 第3章
在创建对象时必须
A:先声明对象,然后才能使用对象
B:先声明对象,为对象分配内存空间,然后才能使用对象
C:先声明对象,为对象分配内存空间,对对象初始化,然后才能使用对象
D:上述说法都对
答案:C
第8题 (1.0分) 题号:7324 难度:中 第3章
设 A为已定义的类名,下列声明并创建A类的对象a的语句中正确的是?
A:A a=new A();
B:public Aa=A( );
C:A a=new class( );
D:a A;
答案:A
第9题 (1.0分) 题号:7327 难度:中 第3章
下面哪个关键字在定义类头时用不到?
A:class
B:public
C:extends
D:int
答案:D
第10题 (1.0分) 题号:7336 难度:中 第4章
this在程序中代表的是 ?
A:类的对象
B:属性
C:方法
D:父类
答案:A
第11题 (1.0分) 题号:7362 难度:中 第5章
在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或顺序各不相同,返回的值也可以不相同.这种面向对象程序特性称为?
A:隐藏
B:覆盖
C:重载
D:Java不支持此特性
答案:C
第12题 (1.0分) 题号:7342 难度:中 第6章
下列关于静态方法的描述中,错误的是
A:静态方法属于类的共享成员
B:静态方法是通过"类名.方法名"的方式来调用
C:静态方法只能被类调用,不能被对象调用
D:静态方法中可以访问静态变量
答案:C
第13题 (1.0分) 题号:7343 难度:中 第6章
下面哪个关键字用来修饰静态()
A:static
B:protected
C:public
D:private
答案:A
第14题 (1.0分) 题号:7349 难度:中 第7章
父子类在同一个包中,子类不能继承父类的哪个属性()
A:default
B:protected
C:public
D:private
答案:D
第15题 (1.0分) 题号:7346 难度:中 第7章
已知类的继承关系如下:
class A
class Bextends A
class Cextends A
则以下语句中能够通过编译的是?
A:A a=newB();
B:C c=newB();
C:C c=newA();
D:B b=newC();
答案:A
第16题 (1.0分) 题号:7355 难度:中 第8章
下面哪个关键字用于将类中的属性私有化()
A:default
B:protected
C:public
D:private
答案:D
第17题 (1.0分) 题号:7356 难度:中 第8章
下面哪两个关键字是类的可见性修饰符()
A:public和默认的
B:public和private
C:private和默认的
D:protected和默认的
答案:A
第18题 (1.0分) 题号:7364 难度:中 第9章
以下关于方法的覆盖的说法,错误的是()
A:子类的方法与父类的方法,方法名必须相同
B:子类的方法与父类的方法,参数形式必须相同
C:子类的方法与父类的方法,返回值类型必须相同
D:以上都不对
答案:D
第19题 (1.0分) 题号:7368 难度:中 第10章
下面关于抽象类的描述,错误的是()
A:抽象类的修饰符可以是public
B:抽象类的修饰符可以是默认的
C:抽象类中可以有抽象方法,也可以有非抽象方法
D:抽象类中可以有抽象方法,但不可以有非抽象方法
答案:D
第20题 (1.0分) 题号:7373 难度:中 第11章
下列类头定义中,错误的是 ?
A:public xextends y
B:publicclass x extends y
C:class xextends y implements y1
D:class x
答案:A
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1066 难度:中 第1章
what is theresult when you compile and run the following code?
importjava.awt.*;
class Example
{
public static void main(String []args)
{
int Output=10;
boolean b1=false;
if((b1==true)&&(Output+=10)==20))
{
System.out.println("we are equal "+Output);
}
else
System.out.println("not equal "+Output);
}
}
Select allright answer:
A:compileerror ,attempting to perform binary comparison on logical data type
B:Compilationand output of "we are equal 10"
C:compilationand output of "not equal 20"
D:compilationand output of "not equal 10"
答案:D
第2题 (2.0分) 题号:445 难度:中 第1章
下列哪些是Java语言中的保留字
A:if
B:sizeof
C:private
D:null
答案:ACD
第3题 (2.0分) 题号:1058 难度:中 第1章
what is theresult when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
Strings="Hello"
Select allright answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第4题 (2.0分) 题号:1050 难度:中 第2章
What appearsin the standard output when the method named testing is invoked?
classExample{
public static void main(String as[]){
new Example().testing();
}
void testing(){
two:
for (int i=0;i<3;i++){
three:
for (int j=10;j<30;j+=10){
System.out.println(i+j);
if(i>2){continue two;}
}
}
}
}
select allright answers:
A:10 and 20
B:11 and 21
C:12 and 22
D:13 and 23
E:30,31,32,33
答案:ABC
第5题 (2.0分) 题号:1005 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
int i=0;j=5;
st:for( ; ; i++){
for( ; ; j--){
if(i>j) { break st;}
}
}
System.out.println("i="+i+"j="+j);
}
}
A:i=0 j=-1
B:i=1 j=0
C:i=0 j=1
D:i=1 j=-1
E:Compileerror at line 4
答案:A
第6题 (2.0分) 题号:931 难度:中 第2章
现有:
1. class WhileTests {
2. public static void main (String [] args) {
3. int x=5;
4. while (++x<4) {
5. --x;
6. }
7. System.out.println( "x="+x);
8. }
9. }
结果是什么?
A:x=6
B:x=5
C:x=2
D:编译失败
答案:A
第7题 (2.0分) 题号:982 难度:中 第2章
pubic classExample{
public static void main(String[] args){
byte m;
swtich(m){
case 0:
System.out.println("case 0");
case 1:
System.out.println("case 1");
break;
case 2:
default:
System.out.println("default");
}
}
}
Which valueof m would cause "default" to be the output?
A:0
B:1
C:2
D:3
答案:CD
第8题 (2.0分) 题号:985 难度:中 第2章
pubic classExample{
public static void main(String[] args){
char mychar='c';
switch(mychar){
default:
char 'a':
System.out.println("a");
break ;
char 'b':
System.out.println("a");
break ;
}
}
}
Which of thefollowing questions are definitely true?
A:this switchblock is illegal,because only integers can be used in the switch statement
B:this switchblock is fine
C:this switchblock is illegal,because the default statement must come last
D:when thiscodes runs,nothing is written to the standard output
E:When thiscodes runs,the letter "a" is written to the standard output
答案:BE
第9题 (2.0分) 题号:966 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public staticvoid main(String [] args)
{
Example a=new Example();
a.method();
}
public voidamehtod ()
{System.out.println(j);
System.out.println(b);
}
}
Select allright answer?
A:compilationsucceeds and at run time on output of 0 and false
B:compilationsucceds and at run time an output of 0 and true
C:compiletime error b is not initialised
D:compiletime error z must be assigned a char value
答案:A
第10题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:publicprotected amethod(int i)
B:public voidamethod(int i)
C:public voidamethod(void)
D:void publicamethod(int i)
答案:B
第11题 (2.0分) 题号:980 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{ void fun()
{
static int i=0;
}
public staticvoid main(String [] args)
{ Example obj=new Example();
obj.fun();
obj.fun();
}
}
Select allright answer:
A:1
B:2
C:compilationerror
D:run timeerror
答案:C
第12题 (2.0分) 题号:977 难度:中 第3章
what is theresult when you compil and run the following code?
class Example
{
static int myArg=1;
public staticvoid main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select allright answer:
A:this codecompiles and displays 0 in the statndard output when run
B:this code compilesand displays 1 in the statndard output when run
C:this codedoes not compile because you can't define a local variable names the same asstatic variable
D:this codedoesn't compile because the local vriable is used before it is initialized
答案:D
第13题 (2.0分) 题号:951 难度:中 第4章
当你试图编译并运行如下代码时会发生什么?
class Base {
int i = 99;
public voidamethod () {
System.out.println("Base.amethod ()");
}
Base () {
amethod ();
}
}
public classRType extends Base {
int i = -1;
public staticvoid main (String argv []) {
Base b = newRType ();
System.out.println(b.i);
b.amethod ();
}
public voidamethod () {
System.out.println("RType.amethod ()");
}
}
A:RType.amethod
-1
RType.amethod
B:RType.amethod
99
RType.amethod
C:99
RType.amethod
D:Compile timeerror
答案:B
第14题 (2.0分) 题号:943 难度:中 第4章
下面的哪一句陈述是正确的?
A:The defaultconstructor has a return type of void
B:The defaultconstructor takes a parameter of void
C:The defaultconstructor takes no parameters
D:The defaultconstructor is not created if the class has any constructors of its own.
答案:CD
第15题 (2.0分) 题号:945 难度:中 第4章
假设有如下类定义
class Mammal{
Mammal () {
System.out.println("Mamml");
}
}
class Dogextends Mammal {
Dog () {
System.out.println("Dog");
}
}
public classCollie extends Dog {
public staticvoid main (String argv []) {
Collie c =new Collie ();
}
Collie () {
this("Good Dog");
System.out.println("Collie");
}
Collie(String s) {
System.out.println(s);
}
}
将会输出什么?
A:Compiletime error
B:Mammal,Dog, Good Dog, Collie
C:Good Dog,Collie, Dog, Mammal
D:Good Dog,Collie
答案:B
第16题 (2.0分) 题号:955 难度:中 第4章
Given:
1. classPlant {
2. StringgetName() { return "plant"; }
3. PlantgetType() { return this; }
4. }
5. class Flowerextends Plant {
6. // insertcode here
7. }
8. classTulip extends Flower { }
Whichstatement(s), inserted at line 6, will compile? (Choose all that apply.)
A:FlowergetType() { return this; }
B:StringgetType() { return "this"; }
C:PlantgetType() { return this; }
D:TulipgetType() { return new Tulip(); }
答案:ACD
第17题 (2.0分) 题号:942 难度:中 第4章
当你试着编译运行下面的类的时候,可能会发生什么?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severnextends Base{
public staticvoid main(String argv[]){
Severn s =new Severn();
}
voidSevern(){
System.out.println("Severn");
}
}
A:Compilationand output of the string "Severn" at runtime
B:Compiletime error
C:Compilationand no output at runtime
D:Compilationand output of the string "Base"
答案:B
第18题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstractclass Base{
abstractpublic void myfunc();
public voidanother(){
System.out.println("Anothermethod");
}
}
public classAbs extends Base{
public staticvoid main(String argv[]){
Abs a = newAbs();
a.amethod();
}
public voidmyfunc(){
System.out.println("Myfunc");
}
public voidamethod(){
myfunc();
}
}
A:The codewill compile and run, printing out the words "My Func"
B:Thecompiler will complain that the Base class has non abstract methods
C:The codewill compile but complain at run time that the Base class has non abstractmethods
D:Thecompiler will complain that the method myfunc in the base class has no body,nobody at all to love it
答案:A
第19题 (2.0分) 题号:936 难度:中 第5章
Given thefollowing,
1. interfaceBase {
2. boolean m1();
3. bytem2(short s);
4. }
Which codefragments will compile? (Choose all that apply.)
A:interfaceBase2 implements Base { }
B:abstractclass Class2 extends Base {
publicboolean m1() { return true; } }
C:abstractclass Class2 implements Base { }
D:abstractclass Class2 implements Base {
publicboolean m1() { return (true); } }
E:classClass2 implements Base {
boolean m1(){ return false; }
byte m2(shorts) { return 42; } }
答案:CD
第20题 (2.0分) 题号:935 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
abstractpublic void myfunc();
public voidanother(){
System.out.println("Anothermethod");
}
}
public classAbs extends Base{
public staticvoid main(String argv[]){
Abs a = newAbs();
a.amethod();
}
public voidmyfunc(){
System.out.println("Myfunc");
}
public voidamethod(){
myfunc();
}
}
A:The codewill compile and run, printing out the words "My Func"
B:Thecompiler will complain that the Base class is not declared as abstract.
C:The codewill compile but complain at run time that the Base class has non abstractmethods
D:Thecompiler will complain that the method myfunc in the base class has no body,nobody at all to love it
答案:B
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:839 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个名为Prog1的类,属性有平时成绩(pingshi),期末成绩(qimo),都为int类型;
不带参数的构造方法,方法有计算并输出总成绩的方法calculateScore(),
计算方式为:总成绩=平时成绩+期末成绩的1/2;在main方法中,创建Prog1对象s,
然后调用calculateScore()方法来输出总成绩。
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:intpingshi;
intqimo;
Prog1(){
pingshi=45;
qimo= 56;
}
voidcalculateScore() {
doublescore = pingshi + qimo * 0.5;
System.out.print("分数为:" + score);
}
publicstatic void main(String[] args) {
Prog1s = new Prog1();
s.calculateScore();
}
第2题 (10.0分) 题号:927 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个MP3类,要求如下:
(a)属性包括:MP3品牌brand(String类型)、颜色color(String类型)和存储容量capacity(double类型),
并且所有属性为私有。
(b)至少提供一个有参的构造方法(要求品牌和颜色可以初始化为任意值,但存储容量的初始值必须为0)。
(c)为私有属性提供访问器方法。
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
MP3 m1=new MP3("ipod","white");
}
}
答案:classMP3 {
private String brand;
private String color;
private double capacity;
public MP3(String brand,String color){
this.brand=brand;
this.color=color;
capacity=0;
}
public double getCapacity() {
return capacity;
}
public void setCapacity(double capacity) {
this.capacity = capacity;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getBrand() {
return brand;
}
}
第3题 (10.0分) 题号:846 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Apple,子类定义了自己的属性String 类型的类别(kind),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Apple类的编写。
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account) {
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Appleextends Goods {
/**********Program**********/
String kind;
public Apple(double unitPrice,doubleaccount,String kind){
super(unitPrice,account);
this.kind=kind;
}
void show(){
super.show();
System.out.println(kind);
}
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
答案:Stringkind;
Apple(doubleunitPrice, double account, String kind) {
super(unitPrice,account);
this.kind= kind;
}
doubletotalPrice() {
returnunitPrice * account;
}
voidshow() {
System.out.println("苹果的类别是" + kind);
super.show();
}
第4题 (10.0分) 题号:903 难度:中 第21章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:声明一个抽象类Car,该类有颜色color(String类型)
和汽车速度speed(double类型)两个私有属性,有带一个参数的构造
方法,能够利用参数初始化颜色Color。有两个私有属性的访问器方法。
还有一个抽象的startup方法,该方法无返回值无参。
再声明一个Car的子类Benz。该类覆盖startup方法,输出“benz startup”
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public class Prog1{
public static void main(String[] args){
Car c1 = new Benz("black");
}
}
答案:abstractclass Car
{
private String color;
private double speed;
public Car(String color){
this.color = color;
}
public void setColor(String color)
{
this.color = color;
}
public String getColor(){
return color;
}
public void setSpeed(double speed){
this.speed = speed;
}
public double getSpeed(){
return speed;
}
abstract void startup();
}
classBenz extends Car{
public Benz(String color){
super(color);
}
public void startup(){
System.out.println("benzstartup");
}
}
试卷编号:25115
所属语言:Java
试卷方案:Java阶段测试二
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:6540 难度:中 第1章
指出下列类型转换中正确的是
A:int i=8.3;
B:longL=8.4f;
C:inti=(boolean)8.9;
D:double d =100;
答案:D
第2题 (1.0分) 题号:6543 难度:中 第1章
下列单词中,不属于Java关键字的是
A:NULL
B:class
C:this
D:byte
答案:A
第3题 (1.0分) 题号:7299 难度:中 第1章
Java语言中,占用32位存储空间的是
A:long,double
B:long,float
C:int,double
D:int,float
答案:D
第4题 (1.0分) 题号:7305 难度:中 第2章
下列对Java语言的叙述中,错误的是
A:Java虚拟机解释执行字节码
B:Java中执行跳转功能的语句是switch语句
C:Java的类是对具有相同行为对象的一种抽象
D:Java中的垃圾回收机制是一个系统级的线程
答案:B
第5题 (1.0分) 题号:7311 难度:中 第2章
下列语句序列执行后,k 的值是
inti=4,j=5,k=9,m=5;
if(i>j||m<k)k++;
else k--;
A:5
B:9
C:8
D:10
答案:D
第6题 (1.0分) 题号:7304 难度:中 第2章
Java 支持的3 种跳转语句不包括
A:break语句
B:continue语句
C:return语句
D:goto语句
答案:D
第7题 (1.0分) 题号:7333 难度:中 第3章
下面方法定义中,不正确的是:
A:float x(inta,int b){return a-b;}
B:int x(inta,int b){return a-b;}
C:int x(inta,int b){return a*b;}
D:int x(inta,int b){return 1.2*(a-b);}
答案:D
第8题 (1.0分) 题号:7321 难度:中 第3章
若在某一个类定义中定义有如下的方法:static void testMethod( ) 该方法属于 ?
A:本地方法
B:最终方法
C:静态方法
D:抽象方法?
答案:C
第9题 (1.0分) 题号:7329 难度:中 第3章
下列不属于面向对象的三大特征的是 ?
A:继承
B:方法
C:封装
D:多态
答案:B
第10题 (1.0分) 题号:7337 难度:中 第4章
下列对构造方法的调用方式的描述中正确的是?
A:使用new调用
B:使用类名调用
C:使用对象名调用
D:调用方法为对象名.方法名()
答案:A
第11题 (1.0分) 题号:7317 难度:中 第5章
有以下方法的定义,请选择该方法的返回类型?
typemethod(byte x,float y){
return x/y*2;
}
A:byte
B:short
C:int
D:float
答案:D
第12题 (1.0分) 题号:7319 难度:中 第6章
为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式可能为?
A:static voidmethod( )
B:public voidmethod( )
C:final voidmethod( )
D:abstractvoid method( )
答案:A
第13题 (1.0分) 题号:7344 难度:中 第6章
下面哪个关键字用来修饰常量()
A:static
B:final
C:public
D:private
答案:B
第14题 (1.0分) 题号:7348 难度:中 第7章
继承的关键字是()
A:extend
B:extends
C:Extend
D:Extends
答案:B
第15题 (1.0分) 题号:7351 难度:中 第7章
关于super的说法正确的是( ).
A:是指当前对象的内存地址
B:是指当前对象的父类对象的内存地址
C:是指当前对象的父类
D:可以用在main()方法中
答案:B
第16题 (1.0分) 题号:7357 难度:中 第8章
下面关于属性的修饰符,哪个只能在当前类中使用()
A:default
B:protected
C:public
D:private
答案:D
第17题 (1.0分) 题号:7359 难度:中 第8章
下面关于get和set方法的叙述,正确的是()
A:两个方法一般都有返回值
B:两个方法一般都没有返回值
C:get方法一般有返回值
D:set方法一般有返回值
答案:C
第18题 (1.0分) 题号:7366 难度:中 第9章
下面关于多态性的说法,正确的是()
A:一个类中不能有同名的方法
B:子类中不能有和父类中同名的方法
C:子类中可以有和父类中同名且参数相同的方法
D:多态性就是方法的名字可以一样,但返回的类型必须不一样
答案:C
第19题 (1.0分) 题号:7369 难度:中 第10章
下面说法正确的是().
A:final可修饰类、属性、方法.
B:abstract可修饰类、属性、方法.
C:定义抽象方法需要给出方法的返回值类型、方法名、参数列表和方法体.
D:用final修饰的变量,在程序中可对这个变量的值进行修改.
答案:A
第20题 (1.0分) 题号:7372 难度:中 第11章
在使用interface声明一个接口时,只可以使用哪个修饰符修饰该接口.
A:private
B:protected
C:private或者protected
D:public
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:919 难度:中 第1章
下列哪项是int类型的字面量?
A:\u03A6
B:077
C:0xABBC
D:-20
答案:BCD
第2题 (2.0分) 题号:441 难度:中 第1章
what is theresult when you compile and run the following code?
class Example
{
public static void main(String []args)
{
int i=1;
int j;
j=i++;
System.out.print(i+","+j);
}
}
Select allright answer:
A:1,1
B:1,2
C:2,1
D:2,2
答案:C
第3题 (2.0分) 题号:1057 难度:中 第1章
what is theresult when you compile and run the following code?
class Example
{
public static void main(String []args)
{
long x=42L;
long y=44L;
System.out.println(""+7+2+" ");
System.out.println(foo()+x+5+" ");
System.out.println(x+y+foo());
}
static String foo()
{ return "foo";
}
}
Select allright answer:
A:9 foo 47 86foo
B:9 foo 474244foo
C:72 foo 474244 foo
D:72foo 42586 foo
E:72 foo 4254244 foo
F:compilationfails
答案:D
第4题 (2.0分) 题号:995 难度:中 第2章
How can youchange the break statement below so that it breaks out of the inner
and middle loops and continues with the nextiteration of the outer loop?
classExample{
public static void main(String[] args){
outer:for(int x=0;x<3;x++){
middle: for(inty=0;y<3;y++){
inner:for(intz=0;z<3;z++){
break;
}
}
}
}
}
A:breakinner;
B:breakouter;
C:breakmiddle;
D:continue
E:continuemiddle
答案:C
第5题 (2.0分) 题号:1002 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
default:
for(int i=0;i<10;i++)
mid:
for(int j=0;j<5;j++)
System.out.println(j);
}
}
A:print 0-4
B:compiationerror
C:runtimeexception
答案:B
第6题 (2.0分) 题号:932 难度:中 第2章
现有:
1. class Test2 f
2. public static void main (String [] args) {
3. boolean x= true;
4. boolean y=false;
5. short z=20;
6.
7. if((x==true) && (y==true)) z++;
8. if((y==true) || (++z==22)) z++;
9.
10. System. out .println( "z="+z);
11. }
12. }
结果是什么?
A:z=21
B:z=22
C:z=23
D:z= 24
答案:A
第7题 (2.0分) 题号:928 难度:中 第2章
class TestApp{
public static void main (String[] args){
int x=5;
switch (x){
case 1:
case 2:
case 3:
System.out.println("一季度");
break;
case 4:
case 5:
case 6:
System. out.println("二季度");
break;
default:
System. out.println("三季度以上");
break;
}
}
}
上述程序运行后的结果是哪项?
A:一季度
B:二季度
C:三季度以上
D:无输出
答案:B
第8题 (2.0分) 题号:999 难度:中 第2章
what is theresult when you compile and run the following code
classExample{
public static void main(String[] args){
int i=1;
int j=10;
do{
if(i>j) {continue;}
j--;
}while(++i<6);
System.out.println("i="+i+"j="+j);
}
}
A:i=4 j=5
B:i=5 j=6
C:i=5 j=5
D:i=4 j=6
E:i=6 j=5
答案:E
第9题 (2.0分) 题号:976 难度:中 第3章
你如何在类中实现封装?
A:make allvariables protected and only allow access via methods
B:make allvariables private and only allow access via methods
C:ensure allvariables are represented by wrapper classes
D:ensure allvariables are accessed through methods in an ancestor class
答案:B
第10题 (2.0分) 题号:969 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{
Integer b=new Integer(10);
new Example().Add(b);
System.out.println(b.intValue());
}
public voidAdd(Integer b)
{
int i=b.intValue();
i+=3;
b=newInteger(i);
}
}
Select allright answer?
A:will print10;
B:will print13;
C:compilationError in Line 4,implicit conversion to Integer to String is not possible
D:Exceptionin line 10
答案:A
第11题 (2.0分) 题号:972 难度:中 第3章
给定下面的类
public classCrowle{
public staticvoid main(String argv[]){
Crowle c =new Crowle();
}
Crowle(){
System.out.println("Greetingsfrom Crowle");
}
}
构造方法会返回哪一种数据类型?
A:null
B:integer
C:String
D:no datatypeis returned
答案:D
第12题 (2.0分) 题号:979 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
staticboolean Paddy;
public staticvoid main(String [] args)
{
System.out.println(Paddy);
}
}
Select allright answer:
A:compiletime error;
B:compilationand output of false;
C:compilationand output of true
D:compilationand output of null
答案:B
第13题 (2.0分) 题号:940 难度:中 第4章
给定下面的类定义
class Base{
Base(int i){}
}
class DefConextends Base{
DefCon(inti){
//XX
}
}
如果将标记//XX 的地方替换为下面的行,哪一行是独立合法的?
A:super();
B:this();
C:this(99);
D:super(99);
答案:D
第14题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog{ }
2. classBeagle extends Dog { }
3.
4. classKennel {
5. publicstatic void main(String [] arfs) {
6. Beagle b1= new Beagle();
7. Dog dog1 =new Dog();
8. Dog dog2 =b1;
9. // insertcode here
10. }
11. }
Which,inserted at line 9, will compile?
A:Beagle b2 =(Beagle) dog1;
B:Beagle b3 =(Beagle) dog2;
C:Beagle b4 =dog2;
D:None of theabove statements will compile
答案:AB
第15题 (2.0分) 题号:952 难度:中 第4章
Given:
classClidders {
public finalvoid flipper() { System.out.println("Clidder"); }
}
public classClidlets extends Clidders {
public voidflipper() {
System.out.println("Flipa Clidlet");
super.flipper();
}
public staticvoid main(String [] args) {
newClidlets().flipper();
}
}
What is theresult?
A:Flip aClidlet
B:Flip aClidder
C:Flip aClidder
Flip aClidlet
D:Flip aClidlet
Flip aClidder
E:Compilationfails.
答案:E
第16题 (2.0分) 题号:949 难度:中 第4章
给定下面的类定义
class Base{
public voidamethod(){
System.out.println("Base");
}
}
public classHay extends Base{
public staticvoid main(String argv[]){
Hay h = newHay();
h.amethod();
}
}
下面在类Hay 中的哪一个方法将会编译并使程序打印出字符串"Hay"?
A:public intamethod(){ System.out.println("Hay");}
B:public voidamethod(long l){ System.out.println("Hay");}
C:public voidamethod(){ System.out.println("Hay");}
D:public voidamethod(void){ System.out.println("Hay");}
答案:C
第17题 (2.0分) 题号:950 难度:中 第4章
假设你被给予如下设计
"一个人有姓名,年龄,地址和性别。你将要设计一个类来表示一类叫做病人的人。这种人
可以被给予诊断,有配偶并且可能活着"。假设表示人的类已经创建了,当你设计病人类时
如下哪些应该被包含在内?
A:registrationdate
B:age
C:sex
D:diagnosis
答案:AD
第18题 (2.0分) 题号:449 难度:中 第5章
关于接口的说法中正确的是
A:接口所有的方法都是抽象的
B:接口所有的方法一定都是public属性的
C:用于定义接口的关键字是implements
D:接口是Java中特殊类,包含常量和抽象方法
答案:ABD
第19题 (2.0分) 题号:938 难度:中 第5章
Which istrue? (Choose all that apply.)
A:"Xextends Y" is correct if and only if X is a class and Y is an interface.
B:"Xextends Y" is correct if and only if X is an interface and Y is a class.
C:"Xextends Y" is correct if X and Y are either both classes or bothinterfaces.
D:"Xextends Y" is correct for all combinations of X and Y being classes and/orinterfaces.
答案:C
第20题 (2.0分) 题号:443 难度:中 第5章
下列哪些属于Java的数据类型
A:接口
B:无符号整数类型
C:整数类型
D:浮点数类型
答案:ACD
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:841 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个名为Prog1的类,属性包括name(书名,String类型)、author(作者名,String类型)、
price(书的价格,double类型),定义不带参数的构造方法,
定义输出图书基本信息的show方法。在main方法中,创建Prog1类的一个对象b,调用show方法。
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:Stringname;
Stringauthor;
doubleprice;
Prog1(){
name="文化苦旅";
author="余秋雨";
price=56;
}
voidshow(){
System.out.println("书名是"+name);
System.out.println("作者是"+author);
System.out.println("价格是"+price);
}
publicstatic void main(String[] args) {
Prog1b = new Prog1();
b.show();
}
第2题 (10.0分) 题号:931 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:设计一个模拟银行账户功能的类Account,要求如下:
(a)属性:账号(card,字符串类型)、储户姓名(name,字符串类型)、
地址(address,字符串类型)、存款余额(balance,浮点型)、
最低余额(minBalance,浮点型)
(b)方法:初始化所有属性的构造方法、存款(deposit方法)、取款(draw方法)
、查询(query方法)
要求:存款操作需显示储户原有余额、将要存款数额及最终存款余额;
取款时,若最后余额小于最小余额,拒绝取款并显示"取款失败,至少保留余额XXX";
查询操作能显示储户账号、姓名、地址、存款余额及最低余额。
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Account a=newAccount("001","John","大连",1000);
Account.minBalance=200;
a.deposit(500);
a.draw(2000);
a.query();
}
}
答案:publicclass Account {
String card;
String name;
String address;
double balance;
static double minBalance;
public Account(String card,String name,Stringaddress,double balance){
this.card=card;
this.name=name;
this.address=address;
this.balance=balance;
}
public void deposit(double n){
System.out.println("原有余额:"+balance);
System.out.println("将要存款额:"+n);
this.balance=this.balance+n;
System.out.println("现有余额:"+balance);
}
public void draw(double m){
if(balance-m<minBalance){
System.out.println("取款失败,至少保留余额"+minBalance);
}
else balance=balance-m;
}
public void query(){
System.out.println("卡号:"+card);
System.out.println("姓名:"+name);
System.out.println("地址:"+address);
System.out.println("余额:"+balance);
System.out.println("最低余额:"+minBalance);
}
}
第3题 (10.0分) 题号:845 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Milk,子类定义了自己的属性double类型的会员价格(vipPrice),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Milk类的编写
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Milkextends Goods {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
答案:doublevipPrice;
Milk(doublen, double p, double vipPrice) {
super(n,p);
this.vipPrice= vipPrice;
}
voidshow() {
super.show();
System.out.println("会员价格是" + vipPrice);
}
第4题 (10.0分) 题号:903 难度:中 第21章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:声明一个抽象类Car,该类有颜色color(String类型)
和汽车速度speed(double类型)两个私有属性,有带一个参数的构造
方法,能够利用参数初始化颜色Color。有两个私有属性的访问器方法。
还有一个抽象的startup方法,该方法无返回值无参。
再声明一个Car的子类Benz。该类覆盖startup方法,输出“benz startup”
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Car c1 = new Benz("black");
}
}
答案:abstractclass Car
{
private String color;
private double speed;
public Car(String color){
this.color = color;
}
public void setColor(String color)
{
this.color = color;
}
public String getColor(){
return color;
}
public void setSpeed(double speed){
this.speed = speed;
}
public double getSpeed(){
return speed;
}
abstract void startup();
}
classBenz extends Car{
public Benz(String color){
super(color);
}
public void startup(){
System.out.println("benzstartup");
}
}
试卷编号:28263
所属语言:Java
试卷方案:Java阶段测试三
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:7300 难度:中 第1章
设int x = 1 ,y = 2 , z = 3,则表达式 y+=z--/++x中y的值是
A:3
B:3.5
C:4
D:4.5
答案:A
第2题 (1.0分) 题号:7298 难度:中 第1章
现有一个变量声明为booleanaa;下面赋值语句中正确的是
A:aa=false;
B:aa=False;
C:aa="true";
D:aa=0;
答案:A
第3题 (1.0分) 题号:6542 难度:中 第1章
下面哪个标识符是合法的
A:#_pound
B:$123+w
C:5Interstate
D:a_b
答案:D
第4题 (1.0分) 题号:7301 难度:中 第2章
下列语句序列执行后,k 的值是( ).
int x=6, y=10, k=5;
switch( x%y ){
case 0: k=x*y;
case 6: k=x/y;
case 12: k=x-y;
default: k=x*y-x;}
A:60
B:5
C:0
D:54
答案:D
第5题 (1.0分) 题号:7314 难度:中 第2章
若a和b是整型变量并以正确赋值,以下正确的switch语句是:
A:switch(a+b);{}
B:switch(a+b*3.0){}
C:switch a{}
D:switch(a%b){}
答案:D
第6题 (1.0分) 题号:7311 难度:中 第2章
下列语句序列执行后,k 的值是
inti=4,j=5,k=9,m=5;
if(i>j||m<k)k++;
else k--;
A:5
B:9
C:8
D:10
答案:D
第7题 (1.0分) 题号:7335 难度:中 第3章
设X,Y是已定义的类名,下列声明X类的对象x1的语句正确的是:
A:static Xx1(123);
B:public Xx1=new X(123);
C:Y x1;
D:X x1=X();
答案:B
第8题 (1.0分) 题号:7322 难度:中 第3章
下列方法定义中,方法头不正确的是?
A:double m(int m){ }
B:void m( intm){ }
C:public intm(int m, int n){ }
D:m( inth,int m,int n){ }
答案:D
第9题 (1.0分) 题号:7332 难度:中 第3章
下面方法定义中,正确的是:
A:int x(inta,b){return a-b;}
B:doublex(int a,int b){int w;w=a-b;}
C:doublex(a,b){return b;}
D:int x(inta,int b){return a-b;}
答案:D
第10题 (1.0分) 题号:7339 难度:中 第4章
下列构造方法的调用方式中,正确的是
A:按照一般方法调用
B:由用户直接调用
C:只能通过new自动调用
D:不用调用,自动执行
答案:C
第11题 (1.0分) 题号:7362 难度:中 第5章
在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数的个数、类型或顺序各不相同,返回的值也可以不相同.这种面向对象程序特性称为?
A:隐藏
B:覆盖
C:重载
D:Java不支持此特性
答案:C
第12题 (1.0分) 题号:7341 难度:中 第6章
下列关于静态方法的描述中,错误的是
A:静态方法指的是被static关键字修饰的方法
B:静态方法不占用对象的内存空间,而非静态方法占有对象的内容空间
C:静态方法内可以使用this关键字
D:静态方法内部只能访问被static修饰的成员
答案:C
第13题 (1.0分) 题号:7344 难度:中 第6章
下面哪个关键字用来修饰常量()
A:static
B:final
C:public
D:private
答案:B
第14题 (1.0分) 题号:7347 难度:中 第7章
下面关于super的说法,错误的是()
A:使用super,可以调用父类的构造方法
B:使用super,可以调用父类的属性
C:使用super,可以调用父类的方法
D:使用super,可以调用对象自己的属性和方法
答案:D
第15题 (1.0分) 题号:7349 难度:中 第7章
父子类在同一个包中,子类不能继承父类的哪个属性()
A:default
B:protected
C:public
D:private
答案:D
第16题 (1.0分) 题号:7359 难度:中 第8章
下面关于get和set方法的叙述,正确的是()
A:两个方法一般都有返回值
B:两个方法一般都没有返回值
C:get方法一般有返回值
D:set方法一般有返回值
答案:C
第17题 (1.0分) 题号:7356 难度:中 第8章
下面哪两个关键字是类的可见性修饰符()
A:public和默认的
B:public和private
C:private和默认的
D:protected和默认的
答案:A
第18题 (1.0分) 题号:7365 难度:中 第9章
覆盖与重载的关系是:( )
A:覆盖只有发生在父类与子类之间,而重载可以发生在同一个类中
B:覆盖方法可以不同名,而重载方法必须同名
C:final修饰的方法可以被覆盖,但不能被重载
D:覆盖与重载是同一回事
答案:A
第19题 (1.0分) 题号:7368 难度:中 第10章
下面关于抽象类的描述,错误的是()
A:抽象类的修饰符可以是public
B:抽象类的修饰符可以是默认的
C:抽象类中可以有抽象方法,也可以有非抽象方法
D:抽象类中可以有抽象方法,但不可以有非抽象方法
答案:D
第20题 (1.0分) 题号:7372 难度:中 第11章
在使用interface声明一个接口时,只可以使用哪个修饰符修饰该接口.
A:private
B:protected
C:private或者protected
D:public
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:445 难度:中 第1章
下列哪些是Java语言中的保留字
A:if
B:sizeof
C:private
D:null
答案:ACD
第2题 (2.0分) 题号:1063 难度:中 第1章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{ int i=012;
int j=034;
int k=056;
int l=078
System.out.println(i);
System.out.println(j);
System.out.println(k);
}
}
Select allright answer:
A:prints 12,34 and 56
B:prints 24,68and 112
C:prints 10,28and 46
D:compilationerror
答案:D
第3题 (2.0分) 题号:1061 难度:中 第1章
给定下面的类定义
public classUpton{
public staticvoid main(String argv[]){
}
public voidamethod(int i){}
//Here
}
下面哪一个在替换//Here后是合法的?
A:public intamethod(int z){}
B:public intamethod(int i,int j){return 99;}
C:protectedvoid amethod(long l){ }
D:privatevoid anothermethod(){}
答案:BCD
第4题 (2.0分) 题号:1058 难度:中 第1章
what is theresult when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
Strings="Hello"
Select allright answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第5题 (2.0分) 题号:1054 难度:中 第2章
What is theresult when you compile and run the following code?
public classExample {
public staticvoid main(String args[]){
outer: for(int i=0; i < 3;i++) {
inner: for(int j=0; j<3; j++) {
if(j > 1){break outer; }
System.out.println(j + "and" +i);
}
}
}
}
select allright answer:
A:0 and 0
B:0 and 1
C:0 and 2
D:1 and 0
E:1 and 1
F:1and 2
答案:AD
第6题 (2.0分) 题号:1050 难度:中 第2章
What appearsin the standard output when the method named testing is invoked?
classExample{
public static void main(String as[]){
new Example().testing();
}
void testing(){
two:
for (int i=0;i<3;i++){
three:
for (int j=10;j<30;j+=10){
System.out.println(i+j);
if(i>2){continue two;}
}
}
}
}
select allright answers:
A:10 and 20
B:11 and 21
C:12 and 22
D:13 and 23
E:30,31,32,33
答案:ABC
第7题 (2.0分) 题号:986 难度:中 第2章
what is theresult when you compile and run the following code
pubic classExample{
public static void main(String[] args){
boolean flag=true;
if(flag=true){System.out.println("true");}
else
{System.out.println("false");
}
}
}
A:true isprinted to standard out
B:false isprinted to standard out
C:Anexception is raised
D:Nothinghappens
答案:A
第8题 (2.0分) 题号:1001 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
int x=0;
one:while(x<10){
two: System.out.println(++x);
if(x>3) {break two;}
}
}
}
A:the numbers1 and 2 to the standard output
B:the numbers3 to the standard output
C:this methodwrites the number 0 to the standard output
D:the numbers4 to the standard output
E:the numbers5 through 9 to the standard output
F:the codedoes not compile
答案:F
第9题 (2.0分) 题号:933 难度:中 第2章
现有:
1. class Foo {
2. public static void main (String [] args) {
3. int x=0;
4. int y=4;
5. for (int z=0; z<3; z++) {
6. if(x>1&++y<10)
7. y++;
x++;
8. }
9. System. out .println (y);
10. }
11. }
结果是什么?
A:7
B:8
C:10
D:12
E:13
答案:B
第10题 (2.0分) 题号:971 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{ String s;
public static void main(String []args)
{ Example ks=new Example();
int j,i;
i=ks.hai();
j=ks.hello();
System.out.println(i+""+j);
}
int hai()
{
if((s==null)||(s.length()==0)){return 10;}
else return 0;
}
int hello()
{
if((s==null)|(s.length()==20)){return 10;}
else return 0;
}
}
Select allright answer:
A:10 10
B:10 null
C:0 0
D:compilationerror
E:Anexception in hai
F:an exceptonin hello
答案:F
第11题 (2.0分) 题号:969 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{
Integer b=new Integer(10);
new Example().Add(b);
System.out.println(b.intValue());
}
public voidAdd(Integer b)
{
inti=b.intValue();
i+=3;
b=newInteger(i);
}
}
Select allright answer?
A:will print10;
B:will print13;
C:compilationError in Line 4,implicit conversion to Integer to String is not possible
D:Exceptionin line 10
答案:A
第12题 (2.0分) 题号:953 难度:中 第4章
Given:
class Top {
publicTop(String s) { System.out.print("B"); }
}
public classBottom2 extends Top {
public Bottom2(Strings) { System.out.print("D"); }
public staticvoid main(String [] args) {
newBottom2("C");
System.out.println("");
} }
What is theresult?
A:BD
B:DB
C:BDC
D:DBC
E:Compilationfails
答案:E
第13题 (2.0分) 题号:954 难度:中 第4章
Given:
class Clidder{
private finalvoid flipper() { System.out.println("Clidder"); }
}
public classClidlet extends Clidder {
public finalvoid flipper() { System.out.println("Clidlet"); }
public staticvoid main(String [] args) {
newClidlet().flipper();
} }
What is theresult?
A:Clidlet
B:Clidder
C:Clidder
Clidlet
D:Clidlet
Clidder
E:Compilationfails.
答案:A
第14题 (2.0分) 题号:961 难度:中 第4章
Given thefollowing,
1. class X {void do1() { } }
2. class Yextends X { void do2() { } }
3.
4. classChrome {
5. publicstatic void main(String [] args) {
6. X x1 = newX();
7. X x2 = newY();
8. Y y1 = newY();
9. // insertcode here
10. }
11. }
Which,inserted at line 9, will compile?
A:x2.do2();
B:(Y)x2.do2();
C:((Y)x2).do2();
D:None of theabove statements will compile.
答案:C
第15题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstractclass Base{
abstractpublic void myfunc();
public voidanother(){
System.out.println("Anothermethod");
}
}
public classAbs extends Base{
public staticvoid main(String argv[]){
Abs a = newAbs();
a.amethod();
}
public voidmyfunc(){
System.out.println("Myfunc");
}
public voidamethod(){
myfunc();
}
}
A:The codewill compile and run, printing out the words "My Func"
B:Thecompiler will complain that the Base class has non abstract methods
C:The codewill compile but complain at run time that the Base class has non abstractmethods
D:Thecompiler will complain that the method myfunc in the base class has no body,nobody at all to love it
答案:A
第16题 (2.0分) 题号:1110 难度:中 第6章
你希望找到一个更优雅的方式给你的数组赋值而不使用for 循环语句,下面的哪一个能做
到?
A:myArray{
[1]="One";
[2]="Two";
[3]="Three";
}
B:Strings[5]=new String[]{"Zero","One","Two","Three","Four"};
C:Strings[]=new String[] {"Zero","One","Two","Three","Four"};
D:Strings[]=newString[]={"Zero","One","Two","Three","Four"};
答案:C
第17题 (2.0分) 题号:1113 难度:中 第6章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{ Stringelements[]={"for","tea","too"};
Stringfirst=(elements.length>0)?elements[0]:null;
System.out.println(first);
}
}
Select allright answer:
A:compilationfails;
B:anexception thrown at runtime
C:prints:null
D:prints:for
答案:D
第18题 (2.0分) 题号:1125 难度:中 第7章
Given thefollowing code?
public classAccountManager{
private Map accountTotals = newHashMap();
private int retiremantFund;
public int getBalance(StringaccountName){
Integer total =(Integer)accountTotals.get(accountName);
if(total == null)
total =Integer.valueOf(0);
return total.intValue();
}
public void setBalance(StringaccountName, int amount){
accountTotals.put(accountName,Integer.valueOf(amount));
}
}
This class isto be updated to make use of appropriate generic types, with
no changes inbehavior(for better or worse). Which of these steps could be performed?
Select allright answer:
A:Replaceline 2 with
private Map<String, int> accountTotals =new HashMap<String , int >();
B:Replaceline 2 with
private Map<String, Integer>accountTotals = new HashMap<String , Integer >();
C:Replaceline 2 with
private Map<String<Integer>>accountTotals = new HashMap<String<Integer>>();
D:Replaceline 5-8 with
int total = accountTotals.get(accountName);
if (total == null)
total = 0;
return total;
E:Replaceline 5-8 with
Integer total =accountTotals.get(accountName);
if (total == null)
total = 0;
return total;
F:Replaceline 5-8 with
return accountTotals.get(accountName);
答案:BEF
第19题 (2.0分) 题号:1144 难度:中 第8章
what String instancemethod would return true when invoked like this
a.method(b);
wherea="GROUNDhog" and b="groundHOG"
select allanswers
A:equals()
B:toLowercase()
C:toUppercase()
D:equalsIgnoreCase()
E:None of theabove
答案:D
第20题 (2.0分) 题号:1133 难度:中 第8章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{int b=10;
method(i);
}
static voidmethod(int k)
{System.out.println("primitive type call");
}
static void method(Integerk)
{System.out.println("wrapper type call");
}
}
Select allright answer?
A:wrappertype call
B:primitivetype call
C:Compilererror
D:compilesfine ,throws runtime exception
答案:B
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:927 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个MP3类,要求如下:
(a)属性包括:MP3品牌brand(String类型)、颜色color(String类型)和存储容量capacity(double类型),
并且所有属性为私有。
(b)至少提供一个有参的构造方法(要求品牌和颜色可以初始化为任意值,但存储容量的初始值必须为0)。
(c)为私有属性提供访问器方法。
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
MP3 m1=new MP3("ipod","white");
}
}
答案:classMP3 {
private String brand;
private String color;
private double capacity;
public MP3(String brand,String color){
this.brand=brand;
this.color=color;
capacity=0;
}
public double getCapacity() {
return capacity;
}
public void setCapacity(double capacity) {
this.capacity = capacity;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getBrand() {
return brand;
}
}
第2题 (10.0分) 题号:846 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Apple,子类定义了自己的属性String 类型的类别(kind),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Apple类的编写。
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Appleextends Goods {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
答案:Stringkind;
Apple(doubleunitPrice, double account, String kind) {
super(unitPrice,account);
this.kind= kind;
}
doubletotalPrice() {
returnunitPrice * account;
}
voidshow() {
System.out.println("苹果的类别是" + kind);
super.show();
}
第3题 (10.0分) 题号:850 难度:中 第12章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:已知一个int类型的数组a,数组元素分别是{34,56,78,89,90,100},
编写程序取出数组元素的十位数(使用for循环和除法运算)并输出
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
int[] a= {34,56,78,89,90,100} ;
for(inti=0; i<a.length; i++)
System.out.print(a[i]/10%10+"");
}
第4题 (10.0分) 题号:936 难度:中 第14章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:(MapHashMap set)已知某学校的运动场地如下:
场地类型 场地名称
羽毛球 羽毛球场地1 , 羽毛球场地2 ,羽毛球场地3,羽毛球场地4,羽毛球场地5
乒乓球 乒乓球场地1 , 乒乓球场地2 , 乒乓球场地3, 乒乓球场地4
篮球 篮球场地1 , 篮球场地2 , 篮球场地3
请完成下列要求:
1)使用一个Map<String, String[]> map,存放上表中的场地。
2)编写newStadiumfieldList()方法初始化map,并作为返回值返回。
3)编写getStadiumfield(Map<String, String[]> map)输出map的大小,并遍历map,把键和值都输出。
4)在main方法中调用两个方法,运行结果如下所示:
场地类型为 3 种
篮 球 : 场地数量为 3个,分别为 篮球场地1 篮球场地2 篮球场地3
乒乓球 : 场地数量为 4个,分别为 乒乓球场地1 乒乓球场地2 乒乓球场地3 乒乓球场地4
羽毛球 : 场地数量为 5个,分别为 羽毛球场地1 羽毛球场地2 羽毛球场地3 羽毛球场地4 羽毛球场地5
-------------------------------------------------------*/
importjava.util.*;
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
Map<String, String[]> map= newStadiumfield();
getStadiumfield(map);
}
public static Map<String, String[]>newStadiumfield() {
Map<String, String[]> map = newHashMap<String, String[]>();
String[] s1 = { "羽毛球场地1", "羽毛球场地2", "羽毛球场地3", "羽毛球场地4", "羽毛球场地5"};
String[] s2 = { "乒乓球场地1", "乒乓球场地2", "乒乓球场地3", "乒乓球场地4" };
String[] s3 = { "篮球场地1", "篮球场地2", "篮球场地3" };
map.put("羽毛球", s1);
map.put("乒乓球", s2);
map.put("篮 球",s3);
return map;
}
public static voidgetStadiumfield(Map<String, String[]> map) {
System.out.println("场地类型为 "+map.size()+" 种");
Set <String> set = map.keySet();
for (String key : set) {
System.out.print(key + " :" );
String [] s=map.get(key);
System.out.println("场地数量为 "+s.length+"个 ");
for(String value:s){
System.out.print("\t"+value );
}
System.out.println();
}
}
试卷编号:28264
所属语言:Java
试卷方案:Java阶段测试三
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:6540 难度:中 第1章
指出下列类型转换中正确的是
A:int i=8.3;
B:longL=8.4f;
C:inti=(boolean)8.9;
D:double d =100;
答案:D
第2题 (1.0分) 题号:6537 难度:中 第1章
设int x = 2 ,则表达式 ( x + + ) * 3 的值是
A:6
B:9
C:6.0
D:9.0
答案:A
第3题 (1.0分) 题号:7299 难度:中 第1章
Java语言中,占用32位存储空间的是
A:long,double
B:long,float
C:int,double
D:int,float
答案:D
第4题 (1.0分) 题号:7302 难度:中 第2章
以下由 for 语句构成的循环执行的次数是
for(inti=0;i>0;i++)
A:有语法错,不能执行
B:无限次
C:执行1次
D:一次也不执行
答案:D
第5题 (1.0分) 题号:7304 难度:中 第2章
Java 支持的3 种跳转语句不包括
A:break语句
B:continue语句
C:return语句
D:goto语句
答案:D
第6题 (1.0分) 题号:7303 难度:中 第2章
下列语句序列执行后,m的值是
int m=1;
for(inti=5;i>0;i--)
m*=i;
A:15
B:120
C:60
D:0
答案:B
第7题 (1.0分) 题号:7321 难度:中 第3章
若在某一个类定义中定义有如下的方法:static void testMethod( ) 该方法属于 ?
A:本地方法
B:最终方法
C:静态方法
D:抽象方法?
答案:C
第8题 (1.0分) 题号:7333 难度:中 第3章
下面方法定义中,不正确的是:
A:float x(inta,int b){return a-b;}
B:int x(inta,int b){return a-b;}
C:int x(inta,int b){return a*b;}
D:int x(inta,int b){return 1.2*(a-b);}
答案:D
第9题 (1.0分) 题号:7330 难度:中 第3章
下面正确的main方法是
A:publicstatic void main(String args)
B:publicstatic int main(String[] args)
C:publicstatic void main(String[] args)
D:publicfinal void main(String args)
答案:C
第10题 (1.0分) 题号:7338 难度:中 第4章
以下关于构造函数的描述错误的是 ?
A:构造函数的返回类型只能是void型
B:构造函数是类的一种特殊函数,它的方法名必须与类名相同
C:构造函数的主要作用是完成对类的对象的初始化工作
D:一般在创建新对象时,系统会调用构造函数
答案:A
第11题 (1.0分) 题号:7317 难度:中 第5章
有以下方法的定义,请选择该方法的返回类型?
typemethod(byte x,float y){
return x/y*2;
}
A:byte
B:short
C:int
D:float
答案:D
第12题 (1.0分) 题号:7343 难度:中 第6章
下面哪个关键字用来修饰静态()
A:static
B:protected
C:public
D:private
答案:A
第13题 (1.0分) 题号:7342 难度:中 第6章
下列关于静态方法的描述中,错误的是
A:静态方法属于类的共享成员
B:静态方法是通过"类名.方法名"的方式来调用
C:静态方法只能被类调用,不能被对象调用
D:静态方法中可以访问静态变量
答案:C
第14题 (1.0分) 题号:7352 难度:中 第7章
父子类不在同一个包中,子类能继承父类的哪个属性()
A:default
B:protected
C:static
D:private
答案:B
第15题 (1.0分) 题号:7346 难度:中 第7章
已知类的继承关系如下:
class A
class Bextends A
class Cextends A
则以下语句中能够通过编译的是?
A:A a=newB();
B:C c=newB();
C:C c=newA();
D:B b=newC();
答案:A
第16题 (1.0分) 题号:7353 难度:中 第8章
下列修饰符中,成员内部被()修饰后,不可以被外界访问.
A:default
B:protected
C:public
D:private
答案:D
第17题 (1.0分) 题号:7361 难度:中 第8章
关于类的继承的描述,正确的是()
A:一个类可以继承多个父类
B:一个类可以具有多个子类
C:子类可以使用父类的所有方法
D:子类必须覆盖父类的全部方法
答案:B
第18题 (1.0分) 题号:7364 难度:中 第9章
以下关于方法的覆盖的说法,错误的是()
A:子类的方法与父类的方法,方法名必须相同
B:子类的方法与父类的方法,参数形式必须相同
C:子类的方法与父类的方法,返回值类型必须相同
D:以上都不对
答案:D
第19题 (1.0分) 题号:7369 难度:中 第10章
下面说法正确的是().
A:final可修饰类、属性、方法.
B:abstract可修饰类、属性、方法.
C:定义抽象方法需要给出方法的返回值类型、方法名、参数列表和方法体.
D:用final修饰的变量,在程序中可对这个变量的值进行修改.
答案:A
第20题 (1.0分) 题号:7373 难度:中 第11章
下列类头定义中,错误的是 ?
A:public xextends y
B:publicclass x extends y
C:class xextends y implements y1
D:class x
答案:A
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:921 难度:中 第1章
下列哪项是Java语言中所规定的注释样式?
A://单行注释
B:--单行注释
C:/*
*单行或多行注释
*/
D:/**
*文档注释
*/
答案:ACD
第2题 (2.0分) 题号:1066 难度:中 第1章
what is theresult when you compile and run the following code?
importjava.awt.*;
class Example
{
public static void main(String []args)
{
int Output=10;
boolean b1=false;
if((b1==true)&&(Output+=10)==20))
{
System.out.println("we are equal "+Output);
}
else
System.out.println("not equal "+Output);
}
}
Select allright answer:
A:compileerror ,attempting to perform binary comparison on logical data type
B:Compilationand output of "we are equal 10"
C:compilationand output of "not equal 20"
D:compilationand output of "not equal 10"
答案:D
第3题 (2.0分) 题号:1067 难度:中 第1章
Given:
1. classMaybe {
2. publicstatic void main(String[] args) {
3. boolean b1= true;
4. boolean b2= false;
5.System.out.print(!false ^ false);
6.System.out.print(" " + (!b1 & (b2 = true)));
7.System.out.println(" " + (b2 ^ b1));
8. }
9. }
Which aretrue?
A:Line 5produces true.
B:Line 5produces false.
C:Line 6produces true.
D:Line 6produces false.
E:Line 7produces true.
F:Line 7produces false.
答案:ADF
第4题 (2.0分) 题号:923 难度:中 第1章
现有:
class Test2 {
public static void main (String [] args) {
short a,b,c;
a=1;
b=2;
c=a+b;
a+=2;
}
}
以上代码中,哪一句是错误的?
A:a=1;
B:c=a+b;
C:a+=2;
D:shorta,b,c;
答案:B
第5题 (2.0分) 题号:1005 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
int i=0;j=5;
st:for( ; ; i++){
for( ; ; j--){
if(i>j) { break st;}
}
}
System.out.println("i="+i+"j="+j);
}
}
A:i=0 j=-1
B:i=1 j=0
C:i=0 j=1
D:i=1 j=-1
E:Compileerror at line 4
答案:A
第6题 (2.0分) 题号:1052 难度:中 第2章
What is theresult when you compile and run the following code?
public classExample {
public staticvoid main(String args[]){
for(int i=0;i <= 10; i++) {
if(i > 6){break;}
}
System.out.println(i);
}
}
select allright answer:
A:6
B:7
C:10
D:11
E:Compilationfails
F:Anexception is thrown at runtime
答案:E
第7题 (2.0分) 题号:932 难度:中 第2章
现有:
1. class Test2 f
2. public static void main (String [] args) {
3. boolean x= true;
4. boolean y=false;
5. short z=20;
6.
7. if((x==true) && (y==true)) z++;
8. if((y==true) || (++z==22)) z++;
9.
10. System. out .println( "z="+z);
11. }
12. }
结果是什么?
A:z=21
B:z=22
C:z=23
D:z= 24
答案:A
第8题 (2.0分) 题号:989 难度:中 第2章
classExample{
public static void main(String[] args){
int x
if(x>4){System.out.println("case 1");}
else if(x>9){
System.out.println("case 2");
}
else{System.out.println("case 3");}
}
}
what value ofx will cause case 3 printed in the output
A:less thanzero
B:less 4
C:between 4and 9
D:10 andgreater
E:None
答案:B
第9题 (2.0分) 题号:1002 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
default:
for(int i=0;i<10;i++)
mid:
for(int j=0;j<5;j++)
System.out.println(j);
}
}
A:print 0-4
B:compiationerror
C:runtimeexception
答案:B
第10题 (2.0分) 题号:965 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
int x=12;
publicvoid method(int x)
{
x+=x;
System.out.println(x);
}
public staticvoid main(String [] args)
{
Example t=new Exaple();
t.method(5);
}
}
What is theoutput from the example class?
Select allright answer?
A:5
B:10
C:12
D:17
E:24
答案:B
第11题 (2.0分) 题号:979 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
staticboolean Paddy;
public staticvoid main(String [] args)
{
System.out.println(Paddy);
}
}
Select allright answer:
A:compiletime error;
B:compilationand output of false;
C:compilationand output of true
D:compilationand output of null
答案:B
第12题 (2.0分) 题号:952 难度:中 第4章
Given:
classClidders {
public finalvoid flipper() { System.out.println("Clidder"); }
}
public classClidlets extends Clidders {
public voidflipper() {
System.out.println("Flipa Clidlet");
super.flipper();
}
public staticvoid main(String [] args) {
newClidlets().flipper();
}
}
What is theresult?
A:Flip aClidlet
B:Flip aClidder
C:Flip aClidder
Flip aClidlet
D:Flip aClidlet
Flip aClidder
E:Compilationfails.
答案:E
第13题 (2.0分) 题号:942 难度:中 第4章
当你试着编译运行下面的类的时候,可能会发生什么?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severnextends Base{
public staticvoid main(String argv[]){
Severn s =new Severn();
}
voidSevern(){
System.out.println("Severn");
}
}
A:Compilationand output of the string "Severn" at runtime
B:Compiletime error
C:Compilationand no output at runtime
D:Compilationand output of the string "Base"
答案:B
第14题 (2.0分) 题号:951 难度:中 第4章
当你试图编译并运行如下代码时会发生什么?
class Base {
int i = 99;
public voidamethod () {
System.out.println("Base.amethod ()");
}
Base () {
amethod ();
}
}
public classRType extends Base {
int i = -1;
public staticvoid main (String argv []) {
Base b = newRType ();
System.out.println(b.i);
b.amethod ();
}
public voidamethod () {
System.out.println("RType.amethod ()");
}
}
A:RType.amethod
-1
RType.amethod
B:RType.amethod
99
RType.amethod
C:99
RType.amethod
D:Compiletime error
答案:B
第15题 (2.0分) 题号:937 难度:中 第5章
Which declarea compilable abstract class? (Choose all that apply.)
A:publicabstract class Canine { public Bark speak(); }
B:publicabstract class Canine { public Bark speak() { } }
C:publicclass Canine { public abstract Bark speak(); }
D:publicclass Canine abstract { public abstract Bark speak(); }
答案:B
第16题 (2.0分) 题号:913 难度:中 第6章
你想用下面的代码查找数组最后一个元素的值,当你编译并运行它的时候,会发
生什么?
public classMyAr{
public staticvoid main(String argv[]){
int[] i = newint[5];
System.out.println(i[5]);
}
}
A:Compilationand output of 0
B:Compilationand output of null
C:Compilationand runtime Exception
D:Compiletime error
答案:C
第17题 (2.0分) 题号:1117 难度:中 第6章
what is theresult when you compile and run the following code?
Boolean []b1=new Boolean[10];
boolean[]b2=new Boolean[10];
System.out.println("thevalue of b1[1]="+b1[1]);
System.out.println("thevalue of b2[1]="+b2[1]);
A:prints the valueof b1[1]=false; the value ofb2[1]=false
B:prints the valueof b1[1]=null; the value ofb2[1]=null
C:prints the valueof b1[1]=null; the value ofb2[1]=false
D:prints the valueof b1[1]=false; the value ofb2[1]=null
答案:C
第18题 (2.0分) 题号:1121 难度:中 第7章
A programmerhas an algorithm that requires a java.util.List that provides
an efficientimplementation of add() , but does NOT need to support quick
randomaccess?
Select allright answers:
A:java.util.Queue
B:java.util.ArrayList
C:java.util.LinearSet
D:java.util.LinkedList
答案:D
第19题 (2.0分) 题号:1149 难度:中 第8章
classExample{
public static void main(String[]args){
Stringstr="Welcome";
str.concat("Tojava");
System.out.println(str);
}
}
what will be printed out?
A:the Stringis immutable,Compilation Errors at line 3
B:the Stringis immutable,Run Exception at line 3
C:Prints"Welcome"
D:prints"Welcome To java"
答案:C
第20题 (2.0分) 题号:1151 难度:中 第8章
what is theresult when you compile and run the following code?
String s="hello";
Stringt="hello";
charc[]={'h','e','l','l','o'};
Which willreturn true?select all right answers:
A:s.equals(t)
B:t.equals(c)
C:s==t
D:t.equals(newString ("hello"))
E:t==c
答案:ACD
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:841 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个名为Prog1的类,属性包括name(书名,String类型)、author(作者名,String类型)、
price(书的价格,double类型),定义不带参数的构造方法,
定义输出图书基本信息的show方法。在main方法中,创建Prog1类的一个对象b,调用show方法。
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:Stringname;
Stringauthor;
doubleprice;
Prog1(){
name="文化苦旅";
author="余秋雨";
price=56;
}
voidshow(){
System.out.println("书名是"+name);
System.out.println("作者是"+author);
System.out.println("价格是"+price);
}
publicstatic void main(String[] args) {
Prog1b = new Prog1();
b.show();
}
第2题 (10.0分) 题号:847 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Clothing,子类定义了自己的属性String类型的类别(style),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Clothing类的编写
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
classClothing extends Goods {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
答案:Stringstyle;
Clothing(doubleunitPrice, double account, String style) {
super(unitPrice,account);
this.style= style;
}
voidshow() {
System.out.println("服装的类别是" + style);
super.show();
}
第3题 (10.0分) 题号:849 难度:中 第12章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:已知一个int类型的数组a,数组元素分别是{12,11,78,34},编写程序利用for循环将数组逆序输出。
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
int[] a={ 12,11,78,34};
System.out.println("逆序输入为:");
for(inti=a.length -1;i>=0;i--)
System.out.print(a[i]+"");
}
第4题 (10.0分) 题号:938 难度:中 第14章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
(ArrayList)按要求完成题目编写:
1)创建ArrayList对象list,添加三个字符串对象s1、s2、s3,字符串的值分别为001、002、003
2) 通过for循环对list进行遍历,输出全部字符串
3) 查找是否包含s1,如果存在,删除
4)创建迭代器it ,使用迭代器对list进行遍历,输出全部字符串
-------------------------------------------------------*/
importjava.util.*;
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
ArrayList<String> list = newArrayList<String>();
String s1="001";
String s2="002";
String s3="003";
list.add(s1);
list.add(s2);
list.add(s3);
for (String s : list) {
System.out.println(s);
}
if (list.contains(s1)) {
list.remove(s1);
}
Iterator<String> it =list.iterator();
while (it.hasNext()) {
String s = it.next();
System.out.println(s);
}
}
试卷编号:28265
所属语言:Java
试卷方案:Java阶段测试三
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:6538 难度:中 第1章
关于数据类型转换的说法那个是不正确的
A:Java共有两种数据类型的转换方式:自动转换和强制转换
B:Java中当两个类型不同的运算对象进行二元运算时,Java自动把精度较低的类型转换成另一个精度较高的类型
C:boolean型数据能和其他数据类型进行转换
D:char型和int型数据可以互相转换
答案:C
第2题 (1.0分) 题号:6536 难度:中 第1章
对于一个三位的正整数 n,取出它的十位数字k(k为整型)的表达式是
A:k = n / 10% 10
B:k = n%10 %10
C:k = n % 10
D:k = n / 10
答案:A
第3题 (1.0分) 题号:7296 难度:中 第1章
以下的选项中能正确表示Java语言中的一个整型常量的是
A:12.
B:-20
C:1,000
D:4 5 6
答案:B
第4题 (1.0分) 题号:7306 难度:中 第2章
下列语句中执行跳转功能的语句是
A:for语句
B:while语句
C:continue语句
D:switch语句
答案:C
第5题 (1.0分) 题号:7312 难度:中 第2章
有以下代码,运行完后i的最终值是
int i=1;
int j=i++;
if((i>++j)&&(i++==j)) i+=j;
A:1
B:2
C:3
D:4
答案:B
第6题 (1.0分) 题号:7309 难度:中 第2章
下列语句序列执行后,s的值是
int s=1,i=1;
while(i<=4){
s=s*i;
i++;}
A:6
B:4
C:24
D:5
答案:C
第7题 (1.0分) 题号:7326 难度:中 第3章
下面关于类的结构的说法正确的是 ?
A:类只能包含一个构造方法
B:类可以没有属性
C:类只能包含方法
D:类只能包含属性
答案:B
第8题 (1.0分) 题号:7328 难度:中 第3章
面向对象程序不包含下面的哪个组成部分?
A:类
B:对象
C:接口
D:程序员
答案:D
第9题 (1.0分) 题号:7334 难度:中 第3章
下面方法定义中,正确的是:
A:intx(){char ch='a';return (int)ch;}
B:voidx(){return true;}
C:intx(){return true;}
D:int x(inta,b){return a-b;}
答案:A
第10题 (1.0分) 题号:7336 难度:中 第4章
this在程序中代表的是 ?
A:类的对象
B:属性
C:方法
D:父类
答案:A
第11题 (1.0分) 题号:7363 难度:中 第5章
方法的重载是指,两个方法具有相同名称和不同的参数形式.其中不同的参数形式是指()
A:参数个数和类型不同
B:参数有无返回值
C:方法的修饰符不同
D:以上都不对
答案:A
第12题 (1.0分) 题号:7319 难度:中 第6章
为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式可能为?
A:static voidmethod( )
B:public voidmethod( )
C:final voidmethod( )
D:abstractvoid method( )
答案:A
第13题 (1.0分) 题号:7345 难度:中 第6章
下面关于常量的描述,正确的是()
A:常量在主函数中可以被修改
B:常量在主函数中不可以被修改
C:常量一般用static来定义
D:常量一定会被调用
答案:B
第14题 (1.0分) 题号:7351 难度:中 第7章
关于super的说法正确的是( ).
A:是指当前对象的内存地址
B:是指当前对象的父类对象的内存地址
C:是指当前对象的父类
D:可以用在main()方法中
答案:B
第15题 (1.0分) 题号:7350 难度:中 第7章
下列选项中关于super关键字的说法正确的是()
A:super关键字是在子类对象内部指代其父类对象的引用
B:super关键字不仅可以指代子类的直接父类,还可以指代父类的父类
C:子类通过super关键字只能调用父类的方法,而不能调用父类的属性
D:子类通过super关键字只能调用父类的属性,而不能调用父类的方法
答案:A
第16题 (1.0分) 题号:7357 难度:中 第8章
下面关于属性的修饰符,哪个只能在当前类中使用()
A:default
B:protected
C:public
D:private
答案:D
第17题 (1.0分) 题号:7355 难度:中 第8章
下面哪个关键字用于将类中的属性私有化()
A:default
B:protected
C:public
D:private
答案:D
第18题 (1.0分) 题号:7366 难度:中 第9章
下面关于多态性的说法,正确的是()
A:一个类中不能有同名的方法
B:子类中不能有和父类中同名的方法
C:子类中可以有和父类中同名且参数相同的方法
D:多态性就是方法的名字可以一样,但返回的类型必须不一样
答案:C
第19题 (1.0分) 题号:7367 难度:中 第10章
定义抽象类的关键字是()
A:abstractclass
B:final class
C:staticclass
D:publicclass
答案:A
第20题 (1.0分) 题号:7371 难度:中 第11章
定义一个接口时,下列哪个关键字用不到?
A:public
B:extends
C:interface
D:class
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1060 难度:中 第1章
假设有如下类定义,如下哪些方法可以合法放置在"//Here"的注释之后?
public classRid {
public voidamethod (int i, String s) {}
// Here
}
A:public voidamethod (String s, int i) {}
B:public intamethod (int i, String s) {}
C:public voidamethod (int i, String mystring) {}
D:public voidAmethod (int i, String s) {}
答案:AD
第2题 (2.0分) 题号:442 难度:中 第1章
what is theresult when you compile and run the following code?
class Example
{
public static void main(String []args)
{
int x=5;
boolean y=true;
System.out.print(x<y);
}
}
Select allright answer:
A:a compilererror
B:a runningerror
C:true
D:false
答案:A
第3题 (2.0分) 题号:919 难度:中 第1章
下列哪项是int类型的字面量?
A:\u03A6
B:077
C:0xABBC
D:-20
答案:BCD
第4题 (2.0分) 题号:924 难度:中 第1章
现有代码片段:
String s="123";
String sl=s+456;
请问sl的结果是哪项?
A:123456
B:579
C:编译错误
D:运行时抛出异常
答案:A
第5题 (2.0分) 题号:984 难度:中 第2章
what is theresult when you compile and run the following code?
pubic classExample{
public static void main(String[] args){
int x;
if(x>0){System.out.println("first");}
else if(x>-3){
System.out.println("second");
}
else{System.out.println("third");
}
}
Which rangeof x value would print the string "second"
A:x>0
B:x>-3
C:x<=-3
D:x<=0&x>-3
答案:D
第6题 (2.0分) 题号:983 难度:中 第2章
what is theresult when you compile and run the following code?
pubic classExample{
public static void main(String[] args){
int i=100;
swtich(i){
case 100:
System.out.println(i);
case 200:
System.out.println(i);
case 300:
System.out.println(i);
}
}
}
A:Nothing isprinted
B:Compiletime error
C:the value100,100,100 printed
D:only 100printed
答案:C
第7题 (2.0分) 题号:988 难度:中 第2章
what is theresult when you compile and run the following code
class Example{
public static void main(String[] args){
byte x=2;
switch(x){
case 1:
System.out.println(1);
case 2:
case 3:
System.out.println(3);
case 4:
System.out.println(4);
}
}
}
A:Nothing isprinted out
B:The value 3is printed out
C:The value 3and 4 are printed out
D:The value1,3 and 4 are printed out
答案:C
第8题 (2.0分) 题号:1003 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
new Example().add(5);
}
public void add(int a){
loop:for(int i=1;i<3;i++){
for(intj=1;j<3;j++){
if(a==5) {breakloop;}
}
}
}
}
A:create a runtime error
B:Throw anArrayIndexOutofBoundsException
C:printvalues 1,2,2,4
D:Produces nooutput
答案:D
第9题 (2.0分) 题号:1053 难度:中 第2章
2、 What is the resultwhen you compile and run the following code?
public classExample {
public staticvoid main(String args[]){
int x = 12;
while(x <10) {x--; }
System.out.print(x);
}
}
select allright answer:
A:prints 0
B:prints 10
C:prints 12
D:Line 5 willnever be reached
答案:C
第10题 (2.0分) 题号:966 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public staticvoid main(String [] args)
{
Example a=new Example();
a.method();
}
public voidamehtod ()
{System.out.println(j);
System.out.println(b);
}
}
Select allright answer?
A:compilationsucceeds and at run time on output of 0 and false
B:compilationsucceds and at run time an output of 0 and true
C:compiletime error b is not initialised
D:compiletime error z must be assigned a char value
答案:A
第11题 (2.0分) 题号:977 难度:中 第3章
what is theresult when you compil and run the following code?
class Example
{
static int myArg=1;
public staticvoid main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select allright answer:
A:this codecompiles and displays 0 in the statndard output when run
B:this codecompiles and displays 1 in the statndard output when run
C:this codedoes not compile because you can't define a local variable names the same asstatic variable
D:this codedoesn't compile because the local vriable is used before it is initialized
答案:D
第12题 (2.0分) 题号:963 难度:中 第4章
Given:
class Fizz {
int x = 5;
public staticvoid main(String[] args) {
final Fizz f1= new Fizz();
Fizz f2 = newFizz();
Fizz f3 =FizzSwitch(f1,f2);
System.out.println((f1== f3) + " " + (f1.x == f3.x));
}
static FizzFizzSwitch(Fizz x, Fizz y) {
final Fizz z= x;
z.x = 6;
return z;
} }
What is theresult?
A:true true
B:true false
C:false true
D:false false
E:Compilationfails.
F:Anexception is thrown at runtime.
答案:A
第13题 (2.0分) 题号:962 难度:中 第4章
what is theresult when you compile and run the following code?
class Example
{
static finallong tooth=343L;
static longdoIt(long tooth)
{
System.out.println(++tooth+" ");
return ++tooth;
}
public staticvoid main(String [] args)
{ System.out.println(tooth+" ");
final long tooth=340L;
new Example().doIt(tooth);
System.out.println(tooth);
}
}
Select allright answer:
A:343 340 340
B:343 340 342
C:343 341 342
D:343 341 343
E:343 341 340
F:compilationfails
答案:E
第14题 (2.0分) 题号:945 难度:中 第4章
假设有如下类定义
class Mammal{
Mammal () {
System.out.println("Mamml");
}
}
class Dogextends Mammal {
Dog () {
System.out.println("Dog");
}
}
public classCollie extends Dog {
public staticvoid main (String argv []) {
Collie c =new Collie ();
}
Collie () {
this("Good Dog");
System.out.println("Collie");
}
Collie(String s) {
System.out.println(s);
}
}
将会输出什么?
A:Compiletime error
B:Mammal,Dog, Good Dog, Collie
C:Good Dog,Collie, Dog, Mammal
D:Good Dog,Collie
答案:B
第15题 (2.0分) 题号:935 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
abstractpublic void myfunc();
public voidanother(){
System.out.println("Anothermethod");
}
}
public classAbs extends Base{
public staticvoid main(String argv[]){
Abs a = newAbs();
a.amethod();
}
public voidmyfunc(){
System.out.println("Myfunc");
}
public voidamethod(){
myfunc();
}
}
A:The codewill compile and run, printing out the words "My Func"
B:Thecompiler will complain that the Base class is not declared as abstract.
C:The codewill compile but complain at run time that the Base class has non abstractmethods
D:Thecompiler will complain that the method myfunc in the base class has no body,nobody at all to love it
答案:B
第16题 (2.0分) 题号:1112 难度:中 第6章
Which arelegal declarations? (Choose all that apply.)
A:short x [];
B:short [] y;
C:short[5]x2;
D:short z2[5];
E:short [] z[] [];
F:short [] y2= [5];
答案:ABE
第17题 (2.0分) 题号:1109 难度:中 第6章
你的老板为了你写出了HelloWorld而很高兴地为你升职了,现在她给你分配了一
个新任务,去做一个踢踏舞游戏(或者我小时候玩的曲棍球游戏)。你认为你需要一个多维数组,下面哪一个能做这个工作?
A:int i =newint[3][3];
B:int[] i=new int[3][3];
C:int[][] i=new int[3][3];
D:inti[3][3]=new int[][];
答案:C
第18题 (2.0分) 题号:1126 难度:中 第7章
What is theresult when you compile and run the following code?
importjava.util.*;
public classExample {
private String s;
public Example(String s){
this.s = s;
}
public static void main (String[] args){
HashSet<Object> hs = newHashSet<Object>();
Example ws1 = newExample("aard");
Example ws2 = newExample("aard");
String s1 = newString("aard");
String s2 = newString("aard");
hs.add(ws1);
hs.add(ws2);
hs.add(s1);
hs.add(s2);
System.out.println(hs.size());
}
}
Select allright answer:
A:0
B:1
C:2
D:3
E:4
F:Compilationfails
答案:D
第19题 (2.0分) 题号:1154 难度:中 第8章
what is theresult when you compile and run the following code?
class Example
{ public void myBuf(StringBuffer s,StringBuffers1)
{
s.append("how areyou");
s=s1;
}
public staticvoid main(String [] args)
{
Example tb=new Example();
StringBuffer s=newStringBuffer("hello');
StringBuffer s1=new StringBuffer("doing');
tb.myBuf(s,s1);
System.out.println(s);
}
}
Select allright answer?
A:hello howare you
B:hello
C:hello howare you doing
D:compiletime error
答案:A
第20题 (2.0分) 题号:1148 难度:中 第8章
classExample{
public static void main(String[]args){
String s="ABCD";
s.concat("E");
s.replace('C','F');
System.out.println(s);
}
}
what will be printed out?
A:CompilationErrors says the String is immutable
B:ABFDE
C:ABCDE
D:ABCD
答案:D
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:929 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个教师类Teacher,要求如下:
(a)教师的姓名(name,String类型),所授课程(course,String类型),课时数量(courseNum,int类型)和课时系数(radio,double类型),所有教师的课时系数相同。属性均是私有的。
(b)提供一个有参的构造方法(要求包括姓名,所授课程,课时数量)。
(c)为私有属性提供访问器方法。
(d)定义一个计算课时当量的courseCompute方法(课时当量=课时量*系数),返回值类型为double。
(e)定义一个计算课时费的moneyCompute()方法(课时费=课时当量*钱数,如果当量超过100,每课时30元,当量不超过100每课时20元)
(f)要求所有方法都是共有的
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Teacher.setRadio(1.2);
Teacher t1=new Teacher("张三","Java",64);
System.out.println(t1.getName()+" "+t1.getCourse()+" "+t1.getCourseNum());
double num=t1.courseCompute();
System.out.println("课时当量:"+num);
System.out.println("课时费:"+t1.moneyCompute());
}
}
答案:classTeacher {
private String name;
private String course;
private double courseNum;
private static double radio;
public Teacher(String name,Stringcourse,double courseNum){
this.name=name;
this.course=course;
this.courseNum=courseNum; ;
}
public void setName(String name) {
this.name = name;
}
public void setCourse(String course) {
this.course = course;
}
public void setCourseNum(double courseNum) {
this.courseNum = courseNum;
}
public static void setRadio(double radio) {
Teacher.radio = radio;
}
public String getName(){
return name;
}
public String getCourse(){
return course;
}
public double getCourseNum(){
return courseNum;
}
public static double getRadio(){
return radio;
}
public double courseCompute(){
return courseNum*radio;
}
public double moneyCompute(){
if(this.courseCompute()>100){
return (courseCompute()-100)*30+100*20;
}
else{
return this.courseCompute()*20;
}
}
}
第2题 (10.0分) 题号:843 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Person,在此基础上派生出子类Teacher,子类定义了自己的属性String类型的教师编号(teacherID),
有不带参数的构造方法,覆盖了父类的print方法,调用父类被覆盖的print方法,增加打印自己的属性的语句,
请实现Teacher类的编写。
-------------------------------------------------------*/
class Person{
String id;
String name;
Person(String id, String name) {
this.id = id;
this.name = name;
}
void print() {
System.out.println("id=" + id + ",name =" + name);
}
}
class Teacherextends Person {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args) {
}
}
答案:StringteacherID;
Teacher(){
super("2201212","rose");
teacherID= "10010101";
}
voidprint() {
super.print();
System.out.println("teacherID=" + teacherID);
}
第3题 (10.0分) 题号:852 难度:中 第12章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:某一歌手参加歌曲大奖赛,有30个评委对她的进行打分,存放在一个数组里score[],分数为1到100之间的随机数,
编程利用for循环实现输出这位选手的最高分、最低分和最终得分(最终得分=总分数/评委总人数)
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
int[] score = new int[30];
intmax=0,min=100,sum=0;
double avg=0;
for(int i=0;i<score.length;i++){
score[i]=(int)(Math.random()*100+1);
sum=sum+score[i];
if(max<score[i]) max=score[i];
if(min>score[i]) min=score[i];
}
avg=sum/score.length;
System.out.println("max= "+max);
System.out.println("min= "+min);
System.out.println("avg= "+avg);
}
第4题 (10.0分) 题号:935 难度:中 第14章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
先把信息("0"、 "1"、 "2"、 "3"、 "4")5个字符串存储到ArrayList对象v中,然后通过迭代器i对这个对象进行遍历。
-------------------------------------------------------*/
importjava.util.Vector;
importjava.util.Iterator;
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
// 定义一个动态数组
ArrayList v= new ArrayList();
// 通过循环向数组添加5个元素
for(int i=0;i<5;i++)
{
v.add( String.valueOf(i) );
}
// 把数组对象转换成迭代器对象
Iterator i = v.iterator();
// 通过迭代器对象对数组r元素进行遍历
while(i.hasNext())
{
String s = (String)i.next();
System.out.println(s);
}
}
试卷编号:28266
所属语言:Java
试卷方案:Java阶段测试三
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:6535 难度:中 第1章
设有定义floatx=3.5f, y=4.6f, z=5.7f; 则以下的表达式中,值为true的是
A:x > y ︱︱ x > z
B:x != y
C:z > ( y+ x )
D:y>z
答案:B
第2题 (1.0分) 题号:6539 难度:中 第1章
定义变量int i=3;那么表达式i/6 * 5的计算结果是
A:0
B:1
C:2.5
D:2
答案:A
第3题 (1.0分) 题号:6543 难度:中 第1章
下列单词中,不属于Java关键字的是
A:NULL
B:class
C:this
D:byte
答案:A
第4题 (1.0分) 题号:7310 难度:中 第2章
有以下代码,其中变量i可能的类型是
switch(i){
default:System.out.println("hello");}
A:byte
B:long
C:double
D:A and B
答案:A
第5题 (1.0分) 题号:7307 难度:中 第2章
在switch(expression)语句中,expression的数据类型不能是
A:byte
B:char
C:float
D:short
答案:C
第6题 (1.0分) 题号:7313 难度:中 第2章
下列语句序列执行后,x 的值是
inta=4,b=1,x=6;
if(a==b)x+=a;
else x=++a*x;
A:15
B:30
C:25
D:5
答案:B
第7题 (1.0分) 题号:7331 难度:中 第3章
在创建对象时必须
A:先声明对象,然后才能使用对象
B:先声明对象,为对象分配内存空间,然后才能使用对象
C:先声明对象,为对象分配内存空间,对对象初始化,然后才能使用对象
D:上述说法都对
答案:C
第8题 (1.0分) 题号:7329 难度:中 第3章
下列不属于面向对象的三大特征的是 ?
A:继承
B:方法
C:封装
D:多态
答案:B
第9题 (1.0分) 题号:7324 难度:中 第3章
设 A为已定义的类名,下列声明并创建A类的对象a的语句中正确的是?
A:A a=new A();
B:public Aa=A( );
C:A a=new class( );
D:a A;
答案:A
第10题 (1.0分) 题号:7340 难度:中 第4章
有一个类A,以下为其构造方法的声明,其中正确的是?
A:void A(intx)
B:A(int x)
C:a(int x)
D:void a(intx)
答案:B
第11题 (1.0分) 题号:7363 难度:中 第5章
方法的重载是指,两个方法具有相同名称和不同的参数形式.其中不同的参数形式是指()
A:参数个数和类型不同
B:参数有无返回值
C:方法的修饰符不同
D:以上都不对
答案:A
第12题 (1.0分) 题号:7341 难度:中 第6章
下列关于静态方法的描述中,错误的是
A:静态方法指的是被static关键字修饰的方法
B:静态方法不占用对象的内存空间,而非静态方法占有对象的内容空间
C:静态方法内可以使用this关键字
D:静态方法内部只能访问被static修饰的成员
答案:C
第13题 (1.0分) 题号:7344 难度:中 第6章
下面哪个关键字用来修饰常量()
A:static
B:final
C:public
D:private
答案:B
第14题 (1.0分) 题号:7348 难度:中 第7章
继承的关键字是()
A:extend
B:extends
C:Extend
D:Extends
答案:B
第15题 (1.0分) 题号:7351 难度:中 第7章
关于super的说法正确的是( ).
A:是指当前对象的内存地址
B:是指当前对象的父类对象的内存地址
C:是指当前对象的父类
D:可以用在main()方法中
答案:B
第16题 (1.0分) 题号:7354 难度:中 第8章
被声明为private,protected及public的类成员,在类的外部则()
A:不同包中只能访问到声明为public的成员和有父子类关系的protected的成员
B:只能访问到声明为public和protected的成员
C:都可以访问
D:都不能访问
答案:A
第17题 (1.0分) 题号:7358 难度:中 第8章
下面关于方法的修饰符,哪个只能在当前类中使用()
A:default
B:protected
C:public
D:private
答案:D
第18题 (1.0分) 题号:7364 难度:中 第9章
以下关于方法的覆盖的说法,错误的是()
A:子类的方法与父类的方法,方法名必须相同
B:子类的方法与父类的方法,参数形式必须相同
C:子类的方法与父类的方法,返回值类型必须相同
D:以上都不对
答案:D
第19题 (1.0分) 题号:7368 难度:中 第10章
下面关于抽象类的描述,错误的是()
A:抽象类的修饰符可以是public
B:抽象类的修饰符可以是默认的
C:抽象类中可以有抽象方法,也可以有非抽象方法
D:抽象类中可以有抽象方法,但不可以有非抽象方法
答案:D
第20题 (1.0分) 题号:7371 难度:中 第11章
定义一个接口时,下列哪个关键字用不到?
A:public
B:extends
C:interface
D:class
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1058 难度:中 第1章
what is theresult when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
Strings="Hello"
Select allright answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第2题 (2.0分) 题号:922 难度:中 第1章
现有如下五个声明:
Linel: inta_really_really_really_long_variable_name=5 ;
Line2: int _hi=6;
Line3: int big=7;
Line4:int $dollars=8;
line5: int %opercent=9;
哪行无法通过编译?
A:Line1
B:Line2
C:Line3
D:Line4
E:Line5
答案:E
第3题 (2.0分) 题号:1061 难度:中 第1章
给定下面的类定义
public classUpton{
public staticvoid main(String argv[]){
}
public voidamethod(int i){}
//Here
}
下面哪一个在替换//Here后是合法的?
A:public intamethod(int z){}
B:public intamethod(int i,int j){return 99;}
C:protectedvoid amethod(long l){ }
D:privatevoid anothermethod(){}
答案:BCD
第4题 (2.0分) 题号:440 难度:中 第1章
which results is true when you compile and run thefollowing code?
boolean b1=true;boolean b2=false
Select allright answer:
A:b1==b2
B:b1||b2
C:b1|&b2
D:b1&&b2
答案:A
第5题 (2.0分) 题号:996 难度:中 第2章
classExample{
public static void main(String[] args){
int x=0;
// insert code here
do {}
while(x++<y);
System.out.println(x);
}
}
Which,inserted at line 4,produces the output 12?
A:int y=x;
B:int y=10;
C:int y=11;
D:int y=12;
E:int y=13;
F:None of theabove will allow compilation to succeed
答案:C
第6题 (2.0分) 题号:1000 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
int total=0;
for(int i=0,j=10;totoal>30;++i,--j){
System.out.println("i="+i+"j="+j);
total+=(i+j);
}
System.out.println("Total"+total);
}
}
A:Produce aruntime error
B:produce acompile time error
C:Print out"Total0"
D:Generatethe following as output
i=0 j=10
i=1 j=9
i=2 j=8
答案:C
第7题 (2.0分) 题号:997 难度:中 第2章
what is theresult when you compile and run the following code
classExample{
public static void main(String[] args){
int i=0;
int j=5;
out:for( ; ;i++){
for(; ; j--){
if(i>j) {break out;}
}
}
System.out.println(i+" "+j);
}
}
A:0 5
B:1 -1
C:2 1
D:0 -1
答案:D
第8题 (2.0分) 题号:1049 难度:中 第2章
what codeplaced after the comment //For loop would populate the elements of the arrayia[] with values of the variable i?
public classExample{
public static void main(String argv[]){
Example l=new Example();
l.amethod();
}
public voidamethod(){
int ia[]=new int[4];
//Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
A:for(inti=0;i<ia.length()-1;i++)
B:for(inti=0;i<ia.length();i++)
C:for(inti=1;i<4;i++)
D:for(inti=0;i<ia.length;i++)
答案:D
第9题 (2.0分) 题号:931 难度:中 第2章
现有:
1. class WhileTests {
2. public static void main (String [] args) {
3. int x=5;
4. while (++x<4) {
5. --x;
6. }
7. System.out.println( "x="+x);
8. }
9. }
结果是什么?
A:x=6
B:x=5
C:x=2
D:编译失败
答案:A
第10题 (2.0分) 题号:973 难度:中 第3章
当你试着编译运行下面的代码的时候,可能会发生什么?
public classCrowle{
public staticvoid main(String argv[]){
Crowle c =new Crowle();
}
voidCrowle(){
System.out.println("Greetingsfrom Crowle");
}
}
A:Compilationand output of the string "Greetings from Crowle"
B:Compiletime error, constructors may not have a return type
C:Compilationand output of string "void"
D:Compilationand no output at runtime
答案:D
第11题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:publicprotected amethod(int i)
B:public voidamethod(int i)
C:public voidamethod(void)
D:void publicamethod(int i)
答案:B
第12题 (2.0分) 题号:956 难度:中 第4章
Given:
1. class Zing{
2. protectedHmpf h;
3. }
4. class Woopextends Zing { }
5. class Hmpf{ }
Which istrue? (Choose all that apply.)
A:Woop is-aHmpf and has-a Zing.
B:Zing is-aWoop and has-a Hmpf.
C:Hmpf has-aWoop and Woop is-a Zing.
D:Woop has-aHmpf and Woop is-a Zing.
E:Zing has-aHmpf and Zing is-a Woop.
答案:D
第13题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog{ }
2. classBeagle extends Dog { }
3.
4. classKennel {
5. publicstatic void main(String [] arfs) {
6. Beagle b1= new Beagle();
7. Dog dog1 =new Dog();
8. Dog dog2 =b1;
9. // insertcode here
10. }
11. }
Which,inserted at line 9, will compile?
A:Beagle b2 =(Beagle) dog1;
B:Beagle b3 =(Beagle) dog2;
C:Beagle b4 =dog2;
D:None of theabove statements will compile
答案:AB
第14题 (2.0分) 题号:946 难度:中 第4章
下面哪些论述是正确的?
A:Constructorsare not inherited
B:Constructorscan be overridden
C:A parentalconstructor can be invoked using this
D:Any methodmay contain a call to this or super
答案:A
第15题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstractclass Base{
abstractpublic void myfunc();
public voidanother(){
System.out.println("Anothermethod");
}
}
public classAbs extends Base{
public staticvoid main(String argv[]){
Abs a = newAbs();
a.amethod();
}
public voidmyfunc(){
System.out.println("Myfunc");
}
public voidamethod(){
myfunc();
}
}
A:The codewill compile and run, printing out the words "My Func"
B:Thecompiler will complain that the Base class has non abstract methods
C:The codewill compile but complain at run time that the Base class has non abstractmethods
D:Thecompiler will complain that the method myfunc in the base class has no body,nobody at all to love it
答案:A
第16题 (2.0分) 题号:1117 难度:中 第6章
what is theresult when you compile and run the following code?
Boolean []b1=new Boolean[10];
boolean[]b2=new Boolean[10];
System.out.println("thevalue of b1[1]="+b1[1]);
System.out.println("thevalue of b2[1]="+b2[1]);
A:prints the valueof b1[1]=false; the value ofb2[1]=false
B:prints the valueof b1[1]=null; the value ofb2[1]=null
C:prints the valueof b1[1]=null; the value ofb2[1]=false
D:prints the valueof b1[1]=false; the value ofb2[1]=null
答案:C
第17题 (2.0分) 题号:1116 难度:中 第6章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{ int anar[]=new int[5];
System.out.println(anar[0]);
}
}
Select all rightanswer?
A:Error: anaris referenced before it is initialized
B:Null
C:0
D:5
答案:C
第18题 (2.0分) 题号:1124 难度:中 第7章
Given thefollowing code?
importjava.util.*;
classExample{
public static void main(String[] args){
//insert declaration here
for(int i=0;i <= 10;i++){
List<Integer> row= new ArrayList<Integer>();
for(int j=0; j <=10;j++)
row.add(i * j);
table.add(row);
}
for(List<Integer> row :table)
System.out.println(row);
}
}
Whichstatements could be inserted at //insert declarations here to allow the code tocompile and run?
Select allright answer:
A:List<List<Integer>>table = new List<List<Integer>>();
B:List<List<Integer>>table = new ArrayList<List<Integer>>();
C:List<List<Integer>>table = new ArrayList < ArrayList <Integer>>();
D:List<List,Integer> table = new List< List, Integer >();
E:List<List,Integer> table = new ArrayList< List, Integer >();
F:None ofabove.
答案:B
第19题 (2.0分) 题号:1143 难度:中 第8章
class Polish{
public staticvoid main(String[] args) {
int x = 4;
StringBuffersb = new StringBuffer("..fedcba");
sb.delete(3,6);
sb.insert(3,"az");
if(sb.length()> 6) x = sb.indexOf("b");
sb.delete((x-3),(x-2));
System.out.println(sb);
What is theresult?
A:.faza
B:.fzba
C:..azba
D:..fezba
E:Compilationfails.
答案:C
第20题 (2.0分) 题号:1152 难度:中 第8章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid change(String str, char ch[])
{
Str="changed";
Ch[0]='C';
}
public staticvoid main(String [] args)
{
String str=new String("world');
char ch[]={'H' ,'e'.,'l','l','o'};
change(str, ch);
System.out.println(str+"and"+newString(ch));
}
}
Select allright answer?
A:world andhello
B:world andCello
C:changed andhello
D:changed andCello
答案:B
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:839 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个名为Prog1的类,属性有平时成绩(pingshi),期末成绩(qimo),都为int类型;
不带参数的构造方法,方法有计算并输出总成绩的方法calculateScore(),
计算方式为:总成绩=平时成绩+期末成绩的1/2;在main方法中,创建Prog1对象s,
然后调用calculateScore()方法来输出总成绩。
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:intpingshi;
intqimo;
Prog1(){
pingshi=45;
qimo= 56;
}
voidcalculateScore() {
doublescore = pingshi + qimo * 0.5;
System.out.print("分数为:" + score);
}
publicstatic void main(String[] args) {
Prog1s = new Prog1();
s.calculateScore();
}
第2题 (10.0分) 题号:846 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Apple,子类定义了自己的属性String 类型的类别(kind),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Apple类的编写。
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Appleextends Goods {
/**********Program**********/
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
答案:Stringkind;
Apple(doubleunitPrice, double account, String kind) {
super(unitPrice,account);
this.kind= kind;
}
doubletotalPrice() {
returnunitPrice * account;
}
voidshow() {
System.out.println("苹果的类别是" + kind);
super.show();
}
第3题 (10.0分) 题号:848 难度:中 第12章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:编写程序模拟"挑战杯"演讲大赛,共有10个评委打分,分数为1到10之间的随机数,将10个分数存放在int类型数组score中,
编程利用for循环实现计算歌手的最后得分。
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
int[] score= new int[10];
intmax=0,min=100,sum=0;
double avg=0;
for(int i=0;i<score.length;i++){
score[i]=(int)(Math.random()*10+1);
sum=sum+score[i];
if(max<score[i]) max=score[i];
if(min>score[i]) min=score[i];
}
avg=sum/score.length;
System.out.println("max= "+max);
System.out.println("min= "+min);
System.out.println("avg= "+avg);
}
第4题 (10.0分) 题号:936 难度:中 第14章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:(MapHashMap set)已知某学校的运动场地如下:
场地类型 场地名称
羽毛球 羽毛球场地1 , 羽毛球场地2 ,羽毛球场地3,羽毛球场地4,羽毛球场地5
乒乓球 乒乓球场地1 , 乒乓球场地2 , 乒乓球场地3, 乒乓球场地4
篮球 篮球场地1 , 篮球场地2 , 篮球场地3
请完成下列要求:
1)使用一个Map<String, String[]> map,存放上表中的场地。
2)编写newStadiumfieldList()方法初始化map,并作为返回值返回。
3)编写getStadiumfield(Map<String, String[]> map)输出map的大小,并遍历map,把键和值都输出。
4)在main方法中调用两个方法,运行结果如下所示:
场地类型为 3 种
篮 球 : 场地数量为 3个,分别为 篮球场地1 篮球场地2 篮球场地3
乒乓球 : 场地数量为 4个,分别为 乒乓球场地1 乒乓球场地2 乒乓球场地3 乒乓球场地4
羽毛球 : 场地数量为 5个,分别为 羽毛球场地1 羽毛球场地2 羽毛球场地3 羽毛球场地4 羽毛球场地5
-------------------------------------------------------*/
importjava.util.*;
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
Map<String, String[]> map= newStadiumfield();
getStadiumfield(map);
}
public static Map<String, String[]>newStadiumfield() {
Map<String, String[]> map = newHashMap<String, String[]>();
String[] s1 = { "羽毛球场地1", "羽毛球场地2", "羽毛球场地3", "羽毛球场地4", "羽毛球场地5"};
String[] s2 = { "乒乓球场地1", "乒乓球场地2", "乒乓球场地3", "乒乓球场地4" };
String[] s3 = { "篮球场地1", "篮球场地2", "篮球场地3" };
map.put("羽毛球", s1);
map.put("乒乓球", s2);
map.put("篮 球",s3);
return map;
}
public static voidgetStadiumfield(Map<String, String[]> map) {
System.out.println("场地类型为 "+map.size()+" 种");
Set <String> set = map.keySet();
for (String key : set) {
System.out.print(key + " :" );
String [] s=map.get(key);
System.out.println("场地数量为 "+s.length+"个 ");
for(String value:s){
System.out.print("\t"+value );
}
System.out.println();
}
}
试卷编号:28267
所属语言:Java
试卷方案:Java阶段测试三
试卷总分:100分
共有题型:3种
一、单选 共20题 (共计20分)
第1题 (1.0分) 题号:6541 难度:中 第1章
下列哪一个是合法的标识符
A:12class
B:+viod
C:-5
D:_black
答案:D
第2题 (1.0分) 题号:6540 难度:中 第1章
指出下列类型转换中正确的是
A:int i=8.3;
B:longL=8.4f;
C:inti=(boolean)8.9;
D:double d =100;
答案:D
第3题 (1.0分) 题号:7296 难度:中 第1章
以下的选项中能正确表示Java语言中的一个整型常量的是
A:12.
B:-20
C:1,000
D:4 5 6
答案:B
第4题 (1.0分) 题号:7303 难度:中 第2章
下列语句序列执行后,m的值是
int m=1;
for(inti=5;i>0;i--)
m*=i;
A:15
B:120
C:60
D:0
答案:B
第5题 (1.0分) 题号:7305 难度:中 第2章
下列对Java语言的叙述中,错误的是
A:Java虚拟机解释执行字节码
B:Java中执行跳转功能的语句是switch语句
C:Java的类是对具有相同行为对象的一种抽象
D:Java中的垃圾回收机制是一个系统级的线程
答案:B
第6题 (1.0分) 题号:7308 难度:中 第2章
下列语句序列执行后,i的值是
int i=10;
do { i/=2; } while( i>1 );
A:1
B:5
C:2
D:0
答案:A
第7题 (1.0分) 题号:7333 难度:中 第3章
下面方法定义中,不正确的是:
A:float x(inta,int b){return a-b;}
B:int x(inta,int b){return a-b;}
C:int x(inta,int b){return a*b;}
D:int x(inta,int b){return 1.2*(a-b);}
答案:D
第8题 (1.0分) 题号:7323 难度:中 第3章
设 X 、Y 均为已定义的类名,下列声明类X的对象x1的语句中正确的是?
A:X x1=newX();
B:X x1= X ();
C:X x1=new Y();
D:int X x1;
答案:A
第9题 (1.0分) 题号:7325 难度:中 第3章
下面类的定义中结构正确的是?
A:class A
B:class 2A
C:int class A
D:public class A ()
答案:A
第10题 (1.0分) 题号:7338 难度:中 第4章
以下关于构造函数的描述错误的是 ?
A:构造函数的返回类型只能是void型
B:构造函数是类的一种特殊函数,它的方法名必须与类名相同
C:构造函数的主要作用是完成对类的对象的初始化工作
D:一般在创建新对象时,系统会调用构造函数
答案:A
第11题 (1.0分) 题号:7317 难度:中 第5章
有以下方法的定义,请选择该方法的返回类型?
typemethod(byte x,float y){
return x/y*2;
}
A:byte
B:short
C:int
D:float
答案:D
第12题 (1.0分) 题号:7342 难度:中 第6章
下列关于静态方法的描述中,错误的是
A:静态方法属于类的共享成员
B:静态方法是通过"类名.方法名"的方式来调用
C:静态方法只能被类调用,不能被对象调用
D:静态方法中可以访问静态变量
答案:C
第13题 (1.0分) 题号:7319 难度:中 第6章
为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式可能为?
A:static voidmethod( )
B:public voidmethod( )
C:final voidmethod( )
D:abstractvoid method( )
答案:A
第14题 (1.0分) 题号:7350 难度:中 第7章
下列选项中关于super关键字的说法正确的是()
A:super关键字是在子类对象内部指代其父类对象的引用
B:super关键字不仅可以指代子类的直接父类,还可以指代父类的父类
C:子类通过super关键字只能调用父类的方法,而不能调用父类的属性
D:子类通过super关键字只能调用父类的属性,而不能调用父类的方法
答案:A
第15题 (1.0分) 题号:7347 难度:中 第7章
下面关于super的说法,错误的是()
A:使用super,可以调用父类的构造方法
B:使用super,可以调用父类的属性
C:使用super,可以调用父类的方法
D:使用super,可以调用对象自己的属性和方法
答案:D
第16题 (1.0分) 题号:7360 难度:中 第8章
下面关于get和set方法的叙述,正确的是()
A:两个方法一般都使用this关键字
B:两个方法一般都不使用this关键字
C:set方法不能使用this关键字
D:get方法不能使用this关键字
答案:A
第17题 (1.0分) 题号:7359 难度:中 第8章
下面关于get和set方法的叙述,正确的是()
A:两个方法一般都有返回值
B:两个方法一般都没有返回值
C:get方法一般有返回值
D:set方法一般有返回值
答案:C
第18题 (1.0分) 题号:7366 难度:中 第9章
下面关于多态性的说法,正确的是()
A:一个类中不能有同名的方法
B:子类中不能有和父类中同名的方法
C:子类中可以有和父类中同名且参数相同的方法
D:多态性就是方法的名字可以一样,但返回的类型必须不一样
答案:C
第19题 (1.0分) 题号:7367 难度:中 第10章
定义抽象类的关键字是()
A:abstractclass
B:final class
C:staticclass
D:publicclass
答案:A
第20题 (1.0分) 题号:7373 难度:中 第11章
下列类头定义中,错误的是 ?
A:public xextends y
B:publicclass x extends y
C:class xextends y implements y1
D:class x
答案:A
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1055 难度:中 第1章
which of thefollowing lines of code will compile without error?
A:int i=0;
if (i)System.out.println("Hi");
B:booleanb=true;
booleanb2=true;
if (b==b2)System.out.println("so true");
C:int i=1;
int j=2;
if(i==1 || j==2)System.out.println("OK");
D:int i=1;
int j=2;
if(i==1 &|j==2)System.out.println("OK");
答案:BC
第2题 (2.0分) 题号:923 难度:中 第1章
现有:
class Test2 {
public static void main (String [] args) {
short a,b,c;
a=1;
b=2;
c=a+b;
a+=2;
}
}
以上代码中,哪一句是错误的?
A:a=1;
B:c=a+b;
C:a+=2;
D:shorta,b,c;
答案:B
第3题 (2.0分) 题号:1059 难度:中 第1章
Which arevalid declarations?
A:int $x;
B:int 123;
C:int _123;
D:int %percent;
E:int*divide;
F:intcentral_sales_region_Summer_2005_gross_sales;
答案:ACF
第4题 (2.0分) 题号:1064 难度:中 第1章
what is theresult when you compile and run the following code?
class Example
{
public staticvoid main(String [] args)
{ byte B=10;
byte D=12;
byte I=B*D;
}
}
Select allright answer:
A:the codewill compile and run
B:compiletime error while declaring variable
C:compiletime error while multiplication
D:none of theabove
答案:C
第5题 (2.0分) 题号:988 难度:中 第2章
what is theresult when you compile and run the following code
class Example{
public static void main(String[] args){
byte x=2;
switch(x){
case 1:
System.out.println(1);
case 2:
case 3:
System.out.println(3);
case 4:
System.out.println(4);
}
}
}
A:Nothing isprinted out
B:The value 3is printed out
C:The value 3and 4 are printed out
D:The value1,3 and 4 are printed out
答案:C
第6题 (2.0分) 题号:989 难度:中 第2章
classExample{
public static void main(String[] args){
int x
if(x>4){System.out.println("case 1");}
else if(x>9){
System.out.println("case 2");
}
else {System.out.println("case3");}
}
}
what value ofx will cause case 3 printed in the output
A:less thanzero
B:less 4
C:between 4and 9
D:10 andgreater
E:None
答案:B
第7题 (2.0分) 题号:930 难度:中 第2章
现有:
1.class Output (
2.public static voidmain (String[] args) {
3. int i=5;
4. System.out.print("4"+i+" ");
5. System.out.print (i+5+"7");
6. System.out.println (i+"8");
7. }
8. }
结果为:
A:9 9722
B:9 55758
C:45 10758
D:45 9722
答案:C
第8题 (2.0分) 题号:932 难度:中 第2章
现有:
1. class Test2 f
2. public static void main (String [] args) {
3. boolean x= true;
4. boolean y=false;
5. short z=20;
6.
7. if((x==true) && (y==true)) z++;
8. if((y==true) || (++z==22)) z++;
9.
10. System. out .println( "z="+z);
11. }
12. }
结果是什么?
A:z=21
B:z=22
C:z=23
D:z= 24
答案:A
第9题 (2.0分) 题号:1002 难度:中 第2章
what is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
default:
for(int i=0;i<10;i++)
mid:
for(int j=0;j<5;j++)
System.out.println(j);
}
}
A:print 0-4
B:compiationerror
C:runtimeexception
答案:B
第10题 (2.0分) 题号:979 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
static booleanPaddy;
public staticvoid main(String [] args)
{
System.out.println(Paddy);
}
}
Select allright answer:
A:compiletime error;
B:compilation and output of false;
C:compilationand output of true
D:compilationand output of null
答案:B
第11题 (2.0分) 题号:966 难度:中 第3章
what is theresult when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public staticvoid main(String [] args)
{
Example a=new Example();
a.method();
}
public voidamehtod ()
{System.out.println(j);
System.out.println(b);
}
}
Select allright answer?
A:compilationsucceeds and at run time on output of 0 and false
B:compilationsucceds and at run time an output of 0 and true
C:compiletime error b is not initialised
D:compiletime error z must be assigned a char value
答案:A
第12题 (2.0分) 题号:955 难度:中 第4章
Given:
1. classPlant {
2. StringgetName() { return "plant"; }
3. PlantgetType() { return this; }
4. }
5. classFlower extends Plant {
6. // insertcode here
7. }
8. classTulip extends Flower { }
Whichstatement(s), inserted at line 6, will compile? (Choose all that apply.)
A:FlowergetType() { return this; }
B:StringgetType() { return "this"; }
C:PlantgetType() { return this; }
D:TulipgetType() { return new Tulip(); }
答案:ACD
第13题 (2.0分) 题号:941 难度:中 第4章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
public finalvoid amethod(){
System.out.println("amethod");
}
}
public classFin extends Base{
public staticvoid main(String argv[]){
Base b = newBase();
b.amethod();
}
}
A:Compiletime error indicating that a class with any final methods must be declaredfinal itself
B:Compiletime error indicating that you cannot inherit from a class with final methods
C:Run timeerror indicating that Base is not defined as final
D:Success incompilation and output of "amethod" at run time.
答案:D
第14题 (2.0分) 题号:954 难度:中 第4章
Given:
class Clidder{
private finalvoid flipper() { System.out.println("Clidder"); }
}
public classClidlet extends Clidder {
public finalvoid flipper() { System.out.println("Clidlet"); }
public staticvoid main(String [] args) {
newClidlet().flipper();
} }
What is theresult?
A:Clidlet
B:Clidder
C:Clidder
Clidlet
D:Clidlet
Clidder
E:Compilationfails.
答案:A
第15题 (2.0分) 题号:449 难度:中 第5章
关于接口的说法中正确的是
A:接口所有的方法都是抽象的
B:接口所有的方法一定都是public属性的
C:用于定义接口的关键字是implements
D:接口是Java中特殊类,包含常量和抽象方法
答案:ABD
第16题 (2.0分) 题号:1112 难度:中 第6章
Which arelegal declarations? (Choose all that apply.)
A:short x [];
B:short [] y;
C:short[5]x2;
D:short z2[5];
E:short [] z[] [];
F:short [] y2= [5];
答案:ABE
第17题 (2.0分) 题号:1115 难度:中 第6章
which arelegal declarations? Select all right answer?
class Example
{
public staticvoid main(String [] args)
{ Strings[]=new String[6];
System.out.println(s[6]);
}
}
Select allright answer?
A:a null isprinted
B:compiletime error
C:exceptionis thrown
D:nullfollowed by 0 is printed on the screen
答案:C
第18题 (2.0分) 题号:1123 难度:中 第7章
Which is theresult when you compile and run the following code?
classExample{
public static void main(String[] args){
Vector a = new Vector();
a.add (10);
System.out.println(a.get(0));
}
}
Select allright answers:
A:Prints 10
B:Prints 11
C:Compilationserror
答案:A
第19题 (2.0分) 题号:1139 难度:中 第8章
Given:
class Hexy {
public staticvoid main(String[] args) {
Integer i =42;
String s =(i<40)?"life":(i>50)?"universe":"everything";
System.out.println(s);
}
}
What is theresult?
A:null
B:life
C:universe
D:everything
E:Compilationfails.
F:Anexception is thrown at runtime.
答案:D
第20题 (2.0分) 题号:1136 难度:中 第8章
what is theresult when you compile and run the following code?
class Example
{
public static void main(String []args)
{
Short s=newShort("5");
Boolean b;
// insert code here
}
}
Which,insertedindependently at //insert code here?,will compile?
Select allright answer:
A:b=(Numberinstanceof s);
B:b=(sinstanceof Short);
C:b=sinstanceof (Short);
D:b=(sinstanceof Number);
E:b= sinstanceof (Object);
F:b=(sinstanceof String);
答案:BD
三、程序设计 共4题 (共计40分)
第1题 (10.0分) 题号:929 难度:中 第3章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个教师类Teacher,要求如下:
(a)教师的姓名(name,String类型),所授课程(course,String类型),课时数量(courseNum,int类型)和课时系数(radio,double类型),所有教师的课时系数相同。属性均是私有的。
(b)提供一个有参的构造方法(要求包括姓名,所授课程,课时数量)。
(c)为私有属性提供访问器方法。
(d)定义一个计算课时当量的courseCompute方法(课时当量=课时量*系数),返回值类型为double。
(e)定义一个计算课时费的moneyCompute()方法(课时费=课时当量*钱数,如果当量超过100,每课时30元,当量不超过100每课时20元)
(f)要求所有方法都是共有的
-------------------------------------------------------*/
/**********Program**********/
/********** End **********/
public classProg1{
public static void main(String[] args){
Teacher.setRadio(1.2);
Teacher t1=new Teacher("张三","Java",64);
System.out.println(t1.getName()+" "+t1.getCourse()+" "+t1.getCourseNum());
double num=t1.courseCompute();
System.out.println("课时当量:"+num);
System.out.println("课时费:"+t1.moneyCompute());
}
}
答案:classTeacher {
private String name;
private String course;
private double courseNum;
private static double radio;
public Teacher(String name,String course,doublecourseNum){
this.name=name;
this.course=course;
this.courseNum=courseNum; ;
}
public void setName(String name) {
this.name = name;
}
public void setCourse(String course) {
this.course = course;
}
public void setCourseNum(double courseNum) {
this.courseNum = courseNum;
}
public static void setRadio(double radio) {
Teacher.radio = radio;
}
public String getName(){
return name;
}
public String getCourse(){
return course;
}
public double getCourseNum(){
return courseNum;
}
public static double getRadio(){
return radio;
}
public double courseCompute(){
return courseNum*radio;
}
public double moneyCompute(){
if(this.courseCompute()>100){
return(courseCompute()-100)*30+100*20;
}
else{
return this.courseCompute()*20;
}
}
}
第2题 (10.0分) 题号:845 难度:中 第7章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:现有父类Goods,在此基础上派生出子类Milk,子类定义了自己的属性double类型的会员价格(vipPrice),
有带参数的构造方法,覆盖了父类的show方法,调用父类被覆盖的show方法,增加打印自己的属性的语句,
请实现Milk类的编写
-------------------------------------------------------*/
class Goods {
double unitPrice;//单价
double account;//数量
Goods(double unitPrice, double account){
this.unitPrice=unitPrice ;
this.account=account ;
}
double totalPrice() {//计算总价格
return unitPrice * account;
}
void show() {
System.out.println("单价是" + unitPrice);
System.out.println("购买数量为" + account);
System.out.println("购买商品的总金额是" + this.totalPrice());
}
}
class Milkextends Goods {
/**********Program**********/
答案:doublevipPrice;
Milk(doublen, double p, double vipPrice) {
super(n,p);
this.vipPrice= vipPrice;
}
voidshow() {
super.show();
System.out.println("会员价格是" + vipPrice);
}
/********** End **********/
}
public classProg1{
public staticvoid main(String[] args){
}
}
第3题 (10.0分) 题号:851 难度:中 第12章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
题目:定义一个长度为100的布尔型数组,数组名为fig,并用for循环语句将数组所有元素赋值为false
-------------------------------------------------------*/
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
boolean[] fig = new boolean[100];
for(inti=0;i<fig.length;i++){
g[i]=false;
System.out.println("fig[ "+i+"]= "+fig[i]);
}
}
第4题 (10.0分) 题号:937 难度:中 第14章
/*-------------------------------------------------------
【程序设计】
---------------------------------------------------------
(ArrayList)按要求完成题目编写:
1)创建ArrayList对象list,添加三个Integer对象s1、s2、s3,值分别为20、21、22
2) 通过for循环对list进行遍历,输出全部Integer的值
3) 查找是否包含s1,如果存在,删除
4)通过foreach循环对list进行遍历,输出Integer的值
-------------------------------------------------------*/
importjava.util.*;
public classProg1{
/**********Program**********/
/********** End **********/
}
答案:publicstatic void main(String[] args) {
ArrayList<Integer> list = newArrayList<Integer>();
Integer s1 = 20;
Integer s2 = 21;
Integer s3 = 22;
list.add(s1);
list.add(s2);
list.add(s3);
for (int i=0;i<list.size();i++) {
System.out.println(list.get(i));
}
if (list.contains(s1)) {
list.remove(s1);
}
for (Integer s : list) {
System.out.println(s);
}
}