二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1059 难度:中 第1章
Which are valid declarations?
A:int $x;
B:int 123;
C:int _123;
D:int %percent;
E:int *divide;
F:int central_sales_region_Summer_2005_gross_sales;
答案:ACF
第2题 (2.0分) 题号:1058 难度:中 第1章
what is the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第3题 (2.0分) 题号:1062 难度:中 第1章
给定下面的类定义
public class ShrubHill{
public void foregate(String sName){}
//Here
}
下面的哪一个方法可以合法的直接替换//Here?
A:public int foregate(String sName){}
B:public void foregate(StringBuffer sName){}
C:public void foreGate(String sName){}
D:private void foregate(String sType){}
答案:BC
第4题 (2.0分) 题号:989 难度:中 第2章
class Example{
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 of x will cause case 3 printed in the output
A:less than zero
B:less 4
C:between 4 and 9
D:10 and greater
E:None
答案:B
第5题 (2.0分) 题号:984 难度:中 第2章
what is the result when you compile and run the following code?
pubic class Example{
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 range of 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 the value of j when printed
class Example{
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:Compile error
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 you change the break statement below so that it breaks out of the inner
and middle loops and continues with the next iteration of the outer loop?
class Example{
public static void main(String[] args){
outer:for(int x=0;x<3;x++){
middle: for(int y=0;y<3;y++){
inner:for(int z=0;z<3;z++){
break;
}
}
}
}
}
A:break inner;
B:break outer;
C:break middle;
D:continue
E:continue middle
答案:C
第9题 (2.0分) 题号:968 难度:中 第3章
what is the result when you compile and run the following code?
class Use{public int i=10;}
class Example
{
public static void main(String [] args)
{
Example o=new Example();
o.amethod();
}
public void amethod()
{
int i=99;
Use v=new Use();
v.i=30;
another(v, i);
System.out.println (a.i);
}
public void another(User v,int i)
{
i=0;
v.i=20;
Use vh=new Use();
v=vh;
System.out.println (v.i+" "+i+" ");
}
Select all right answer?
A:10 0 30
B:10 0 20
C:20 0 30
D:20 99 30
答案:B
第10题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:public protected amethod(int i)
B:public void amethod(int i)
C:public void amethod(void)
D:void public amethod(int i)
答案:B
第11题 (2.0分) 题号:976 难度:中 第3章
你如何在类中实现封装?
A:make all variables protected and only allow access via methods
B:make all variables private and only allow access via methods
C:ensure all variables are represented by wrapper classes
D:ensure all variables are accessed through methods in an ancestor class
答案:B
第12题 (2.0分) 题号:977 难度:中 第3章
what is the result when you compil and run the following code?
class Example
{
static int myArg=1;
public static void main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select all right answer:
A:this code compiles and displays 0 in the statndard output when run
B:this code compiles and displays 1 in the statndard output when run
C:this code does not compile because you can't define a local variable names the same as static variable
D:this code doesn't compile because the local vriable is used before it is initialized
答案:D
第13题 (2.0分) 题号:953 难度:中 第4章
Given:
class Top {
public Top(String s) { System.out.print("B"); }
}
public class Bottom2 extends Top {
public Bottom2(String s) { System.out.print("D"); }
public static void main(String [] args) {
new Bottom2("C");
System.out.println(" ");
} }
What is the result?
A:BD
B:DB
C:BDC
D:DBC
E:Compilation fails
答案:E
第14题 (2.0分) 题号:941 难度:中 第4章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}
}
A:Compile time error indicating that a class with any final methods must be declared final itself
B:Compile time error indicating that you cannot inherit from a class with final methods
C:Run time error indicating that Base is not defined as final
D:Success in compilation and output of "amethod" at run time.
答案:D
第15题 (2.0分) 题号:955 难度:中 第4章
Given:
1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
A:Flower getType() { return this; }
B:String getType() { return "this"; }
C:Plant getType() { return this; }
D:Tulip getType() { return new Tulip(); }
答案:ACD
第16题 (2.0分) 题号:945 难度:中 第4章
假设有如下类定义
class Mammal {
Mammal () {
System.out.println ("Mamml");
}
}
class Dog extends Mammal {
Dog () {
System.out.println ("Dog");
}
}
public class Collie extends Dog {
public static void main (String argv []) {
Collie c = new Collie ();
}
Collie () {
this ("Good Dog");
System.out.println ("Collie");
}
Collie (String s) {
System.out.println (s);
}
}
将会输出什么?
A:Compile time error
B:Mammal, Dog, Good Dog, Collie
C:Good Dog, Collie, Dog, Mammal
D:Good Dog, Collie
答案:B
第17题 (2.0分) 题号:961 难度:中 第4章
Given the following,
1. class X { void do1() { } }
2. class Y extends X { void do2() { } }
3.
4. class Chrome {
5. public static void main(String [] args) {
6. X x1 = new X();
7. X x2 = new Y();
8. Y y1 = new Y();
9. // insert code here
10. }
11. }
Which, inserted at line 9, will compile?
A:x2.do2();
B:(Y)x2.do2();
C:((Y)x2).do2();
D:None of the above statements will compile.
答案:C
第18题 (2.0分) 题号:938 难度:中 第5章
Which is true? (Choose all that apply.)
A:"X extends Y" is correct if and only if X is a class and Y is an interface.
B:"X extends Y" is correct if and only if X is an interface and Y is a class.
C:"X extends Y" is correct if X and Y are either both classes or both interfaces.
D:"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
答案:C
第19题 (2.0分) 题号:936 难度:中 第5章
Given the following,
1. interface Base {
2. boolean m1 ();
3. byte m2(short s);
4. }
Which code fragments will compile? (Choose all that apply.)
A:interface Base2 implements Base { }
B:abstract class Class2 extends Base {
public boolean m1() { return true; } }
C:abstract class Class2 implements Base { }
D:abstract class Class2 implements Base {
public boolean m1() { return (true); } }
E:class Class2 implements Base {
boolean m1() { return false; }
byte m2(short s) { return 42; } }
答案:CD
第20题 (2.0分) 题号:964 难度:中 第5章
Select the two statements that best indicate a situation with low coupling.
A:The attributes of the class are all private.
B:The class refers to a small number of other objects.
C:The object contains only a small number of variables.
D:The object is referred to using an anonymous variable, not directly.
E:The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.
F:It is unlikely that changes made to one class will require any changes in another.
答案:EF
二、多选 共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:short a,b,c;
答案:B
第3题 (2.0分) 题号:921 难度:中 第1章
下列哪项是Java语言中所规定的注释样式?
A://单行注释
B:--单行注释
C:/*
*单行或多行注释
*/
D:/**
*文档注释
*/
答案:ACD
第4题 (2.0分) 题号:992 难度:中 第2章
what is the result when you compile and run the following code
class Example{
public static void main(String[] args){
int i=1
switch(i){
case 0:System.out.println("zero"); break;
case 1:System.out.println("one");
case 2: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章
class Example{
public static void main(String[] args){
int t=0;
while(1)
{ if(t++<10) break;
}
}
}
what will be the value of t after the while loop?
A:9
B:10
C:11
D:Compilation Error
E:An Exception will occurs
答案:D
第6题 (2.0分) 题号:1005 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:Compile error 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 the result 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 all right answer:
A:10 10
B:10 null
C:0 0
D:compilation error
E:An exception in hai
F:an excepton in hello
答案:F
第10题 (2.0分) 题号:974 难度:中 第3章
当你试着编译运行下面的两个放在同一个目录的文件的时候,可能会发生什么?
//File P1.java
package MyPackage;
class P1{
void afancymethod(){
System.out.println("What a fancy method");
}
}
//File P2.java
public class P2 extends P1{
afancymethod();
}
A:Both compile and P2 outputs "What a fancy method" when run
B:Neither will compile
C:Both compile but P2 has an error at run time
D:P1 compiles cleanly but P2 has an error at compile time
答案:D
第11题 (2.0分) 题号:972 难度:中 第3章
给定下面的类
public class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
Crowle(){
System.out.println("Greetings from Crowle");
}
}
构造方法会返回哪一种数据类型?
A:null
B:integer
C:String
D:no datatype is returned
答案:D
第12题 (2.0分) 题号:965 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int x=12;
public void method(int x)
{
x+=x;
System.out.println(x);
}
public static void main(String [] args)
{
Example t=new Exaple();
t.method(5);
}
}
What is the output from the example class?
Select all right answer?
A:5
B:10
C:12
D:17
E:24
答案:B
第13题 (2.0分) 题号:949 难度:中 第4章
给定下面的类定义
class Base{
public void amethod(){
System.out.println("Base");
}
}
public class Hay extends Base{
public static void main(String argv[]){
Hay h = new Hay();
h.amethod();
}
}
下面在类Hay 中的哪一个方法将会编译并使程序打印出字符串"Hay"?
A:public int amethod(){ System.out.println("Hay");}
B:public void amethod(long l){ System.out.println("Hay");}
C:public void amethod(){ System.out.println("Hay");}
D:public void amethod(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 Minor extends Uber {
Minor() { super(y); y = y + 3; }
public static void main(String [] args) {
new Minor();
System.out.println(y);
} }
What is the result?
A:6
B:7
C:8
D:9
E:Compilation fails.
F:An exception is thrown.
答案:D
第15题 (2.0分) 题号:943 难度:中 第4章
下面的哪一句陈述是正确的?
A:The default constructor has a return type of void
B:The default constructor takes a parameter of void
C:The default constructor takes no parameters
D:The default constructor is not created if the class has any constructors of its own.
答案:CD
第16题 (2.0分) 题号:952 难度:中 第4章
Given:
class Clidders {
public final void flipper() { System.out.println("Clidder"); }
}
public class Clidlets extends Clidders {
public void flipper() {
System.out.println("Flip a Clidlet");
super.flipper();
}
public static void main(String [] args) {
new Clidlets().flipper();
}
}
What is the result?
A:Flip a Clidlet
B:Flip a Clidder
C:Flip a Clidder
Flip a Clidlet
D:Flip a Clidlet
Flip a Clidder
E:Compilation fails.
答案:E
第17题 (2.0分) 题号:950 难度:中 第4章
假设你被给予如下设计
"一个人有姓名,年龄,地址和性别。你将要设计一个类来表示一类叫做病人的人。这种人
可以被给予诊断,有配偶并且可能活着"。假设表示人的类已经创建了,当你设计病人类时
如下哪些应该被包含在内?
A:registration date
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 declare a compilable abstract class? (Choose all that apply.)
A:public abstract class Canine { public Bark speak(); }
B:public abstract class Canine { public Bark speak() { } }
C:public class Canine { public abstract Bark speak(); }
D:public class Canine abstract { public abstract Bark speak(); }
答案:B
第20题 (2.0分) 题号:939 难度:中 第5章
public abstract interface Frobnicate { public void twiddle(String s); }
Which is a correct class? (Choose all that apply.)
A:public abstract class Frob implements Frobnicate {
public abstract void twiddle(String s) { }
}
B:public abstract class Frob implements Frobnicate { }
C:public class Frob extends Frobnicate {
public void twiddle(Integer i) { }
}
D:public class Frob implements Frobnicate {
public void twiddle(Integer i) { }
}
E:public class Frob implements Frobnicate {
public void twiddle(String i) { }
public void twiddle(Integer s) { }
}
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1064 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ byte B=10;
byte D=12;
byte I=B*D;
}
}
Select all right answer:
A:the code will compile and run
B:compile time error while declaring variable
C:compile time error while multiplication
D:none of the above
答案:C
第2题 (2.0分) 题号:445 难度:中 第1章
下列哪些是Java语言中的保留字
A:if
B:sizeof
C:private
D:null
答案:ACD
第3题 (2.0分) 题号:1063 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void 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 all right answer:
A:prints 12,34 and 56
B:prints 24,68and 112
C:prints 10,28and 46
D:compilation error
答案:D
第4题 (2.0分) 题号:996 难度:中 第2章
class Example{
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 the above 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 the result when you compile and run the following code?
public class Example {
public static void 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 range of value x would produce of output "Test 2"?
select all right answer:
A:x < 4
B:x > 4
C:x > 9
D:None
答案:D
第7题 (2.0分) 题号:990 难度:中 第2章
what is the result when 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 of these
答案:B
第8题 (2.0分) 题号:447 难度:中 第2章
下列哪些属于Java语言的流程控制语句
A:赋值语句
B:分支语句
C:跳转语句
D:循环语句
答案:BCD
第9题 (2.0分) 题号:978 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static int i;
public static void main(String [] args)
{
System.out.println(i);
}
}
Select all right answer:
A:0
B:1
C:null
D:Error variable I may not have been initialized
答案:A
第10题 (2.0分) 题号:981 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=20;
static {int i=10;}
public static void main(String [] args)
{
Example a=new Example();
System.out.println(a.i);
}
}
Select all right answer?
A:prints 10
B:prints 20
C:compilation , variable "i" declared twice
D:compilation error, static initializers for initialization purpose only
答案:B
第11题 (2.0分) 题号:973 难度:中 第3章
当你试着编译运行下面的代码的时候,可能会发生什么?
public class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
void Crowle(){
System.out.println("Greetings from Crowle");
}
}
A:Compilation and output of the string "Greetings from Crowle"
B:Compile time error, constructors may not have a return type
C:Compilation and output of string "void"
D:Compilation and no output at runtime
答案:D
第12题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第13题 (2.0分) 题号:947 难度:中 第4章
试图编译并运行下面代码会发生什么?
class Base {
public void amethod (int i, String s) {
System.out.println ("Base amethod");
}
Base () {
System.out.println ("Base Constructor");
}
}
public class Child extends Base {
int i;
String Parm = "Hello";
public static void main (String argv []) {
Child c = new Child ():
c.amethod ():
}
void amethod (int i, String Parm) {
super.amethod (i, Parm);
}
public void amethod () {}
}
A:Compile time error
B:Error caused by illegal syntax super.amethod (i, Parm)
C:Output of "Base Constructor"
D:Error caused by incorrect parameter names in call to super.amethod
答案:A
第14题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle b1 = new Beagle();
7. Dog dog1 = new Dog();
8. Dog dog2 = b1;
9. // insert code 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 the above statements will compile
答案:AB
第15题 (2.0分) 题号:940 难度:中 第4章
给定下面的类定义
class Base{
Base(int i){}
}
class DefCon extends Base{
DefCon(int i){
//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 static void main(String[] args) {
final Fizz f1 = new Fizz();
Fizz f2 = new Fizz();
Fizz f3 = FizzSwitch(f1,f2);
System.out.println((f1 == f3) + " " + (f1.x == f3.x));
}
static Fizz FizzSwitch(Fizz x, Fizz y) {
final Fizz z = x;
z.x = 6;
return z;
} }
What is the result?
A:true true
B:true false
C:false true
D:false false
E:Compilation fails.
F:An exception is thrown at runtime.
答案:A
第17题 (2.0分) 题号:946 难度:中 第4章
下面哪些论述是正确的?
A:Constructors are not inherited
B:Constructors can be overridden
C:A parental constructor can be invoked using this
D:Any method may 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{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class is not declared as abstract.
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler will complain that the method myfunc in the base class has no body, nobody at all to love it
答案:A
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1066 难度:中 第1章
what is the result when you compile and run the following code?
import java.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 all right answer:
A:compile error ,attempting to perform binary comparison on logical data type
B:Compilation and output of "we are equal 10"
C:compilation and output of "not equal 20"
D:compilation and 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 the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第4题 (2.0分) 题号:1050 难度:中 第2章
What appears in the standard output when the method named testing is invoked?
class Example{
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 all right 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 the result when you compile and run the following code?
class Example{
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:Compile error 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 class Example{
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 value of m would cause "default" to be the output?
A:0
B:1
C:2
D:3
答案:CD
第8题 (2.0分) 题号:985 难度:中 第2章
pubic class Example{
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 the following questions are definitely true?
A:this switch block is illegal,because only integers can be used in the switch statement
B:this switch block is fine
C:this switch block is illegal,because the default statement must come last
D:when this codes runs,nothing is written to the standard output
E:When this codes runs,the letter "a" is written to the standard output
答案:BE
第9题 (2.0分) 题号:966 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public static void main(String [] args)
{
Example a=new Example();
a.method();
}
public void amehtod ()
{ System.out.println(j);
System.out.println(b);
}
}
Select all right answer?
A:compilation succeeds and at run time on output of 0 and false
B:compilation succeds and at run time an output of 0 and true
C:compile time error b is not initialised
D:compile time error z must be assigned a char value
答案:A
第10题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:public protected amethod(int i)
B:public void amethod(int i)
C:public void amethod(void)
D:void public amethod(int i)
答案:B
第11题 (2.0分) 题号:980 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{ void fun()
{
static int i=0;
}
public static void main(String [] args)
{ Example obj=new Example();
obj.fun();
obj.fun();
}
}
Select all right answer:
A:1
B:2
C:compilation error
D:run time error
答案:C
第12题 (2.0分) 题号:977 难度:中 第3章
what is the result when you compil and run the following code?
class Example
{
static int myArg=1;
public static void main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select all right answer:
A:this code compiles and displays 0 in the statndard output when run
B:this code compiles and displays 1 in the statndard output when run
C:this code does not compile because you can't define a local variable names the same as static variable
D:this code doesn't compile because the local vriable is used before it is initialized
答案:D
第13题 (2.0分) 题号:951 难度:中 第4章
当你试图编译并运行如下代码时会发生什么?
class Base {
int i = 99;
public void amethod () {
System.out.println ("Base.amethod ()");
}
Base () {
amethod ();
}
}
public class RType extends Base {
int i = -1;
public static void main (String argv []) {
Base b = new RType ();
System.out.println (b.i);
b.amethod ();
}
public void amethod () {
System.out.println ("RType.amethod ()");
}
}
A:RType.amethod
-1
RType.amethod
B:RType.amethod
99
RType.amethod
C:99
RType.amethod
D:Compile time error
答案:B
第14题 (2.0分) 题号:943 难度:中 第4章
下面的哪一句陈述是正确的?
A:The default constructor has a return type of void
B:The default constructor takes a parameter of void
C:The default constructor takes no parameters
D:The default constructor 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 Dog extends Mammal {
Dog () {
System.out.println ("Dog");
}
}
public class Collie extends Dog {
public static void main (String argv []) {
Collie c = new Collie ();
}
Collie () {
this ("Good Dog");
System.out.println ("Collie");
}
Collie (String s) {
System.out.println (s);
}
}
将会输出什么?
A:Compile time 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. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
A:Flower getType() { return this; }
B:String getType() { return "this"; }
C:Plant getType() { return this; }
D:Tulip getType() { return new Tulip(); }
答案:ACD
第17题 (2.0分) 题号:942 难度:中 第4章
当你试着编译运行下面的类的时候,可能会发生什么?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(String argv[]){
Severn s = new Severn();
}
void Severn(){
System.out.println("Severn");
}
}
A:Compilation and output of the string "Severn" at runtime
B:Compile time error
C:Compilation and no output at runtime
D:Compilation and output of the string "Base"
答案:B
第18题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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 the following,
1. interface Base {
2. boolean m1 ();
3. byte m2(short s);
4. }
Which code fragments will compile? (Choose all that apply.)
A:interface Base2 implements Base { }
B:abstract class Class2 extends Base {
public boolean m1() { return true; } }
C:abstract class Class2 implements Base { }
D:abstract class Class2 implements Base {
public boolean m1() { return (true); } }
E:class Class2 implements Base {
boolean m1() { return false; }
byte m2(short s) { return 42; } }
答案:CD
第20题 (2.0分) 题号:935 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class is not declared as abstract.
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler will complain that the method myfunc in the base class has no body, nobody at all to love it
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:919 难度:中 第1章
下列哪项是int类型的字面量?
A:\u03A6
B:077
C:0xABBC
D:-20
答案:BCD
第2题 (2.0分) 题号:441 难度:中 第1章
what is the result 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 all right answer:
A:1,1
B:1,2
C:2,1
D:2,2
答案:C
第3题 (2.0分) 题号:1057 难度:中 第1章
what is the result 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 all right answer:
A:9 foo 47 86 foo
B:9 foo 47 4244foo
C:72 foo 47 4244 foo
D:72foo 425 86 foo
E:72 foo 425 4244 foo
F:compilation fails
答案:D
第4题 (2.0分) 题号:995 难度:中 第2章
How can you change the break statement below so that it breaks out of the inner
and middle loops and continues with the next iteration of the outer loop?
class Example{
public static void main(String[] args){
outer:for(int x=0;x<3;x++){
middle: for(int y=0;y<3;y++){
inner:for(int z=0;z<3;z++){
break;
}
}
}
}
}
A:break inner;
B:break outer;
C:break middle;
D:continue
E:continue middle
答案:C
第5题 (2.0分) 题号:1002 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:compiation error
C:runtime exception
答案: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 the result when you compile and run the following code
class Example{
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 all variables protected and only allow access via methods
B:make all variables private and only allow access via methods
C:ensure all variables are represented by wrapper classes
D:ensure all variables are accessed through methods in an ancestor class
答案:B
第10题 (2.0分) 题号:969 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{
Integer b=new Integer(10);
new Example().Add(b);
System.out.println(b.intValue());
}
public void Add(Integer b)
{
int i=b.intValue();
i+=3;
b=new Integer(i);
}
}
Select all right answer?
A:will print 10;
B:will print 13;
C:compilation Error in Line 4,implicit conversion to Integer to String is not possible
D:Exception in line 10
答案:A
第11题 (2.0分) 题号:972 难度:中 第3章
给定下面的类
public class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
Crowle(){
System.out.println("Greetings from Crowle");
}
}
构造方法会返回哪一种数据类型?
A:null
B:integer
C:String
D:no datatype is returned
答案:D
第12题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第13题 (2.0分) 题号:940 难度:中 第4章
给定下面的类定义
class Base{
Base(int i){}
}
class DefCon extends Base{
DefCon(int i){
//XX
}
}
如果将标记//XX 的地方替换为下面的行,哪一行是独立合法的?
A:super();
B:this();
C:this(99);
D:super(99);
答案:D
第14题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle b1 = new Beagle();
7. Dog dog1 = new Dog();
8. Dog dog2 = b1;
9. // insert code 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 the above statements will compile
答案:AB
第15题 (2.0分) 题号:952 难度:中 第4章
Given:
class Clidders {
public final void flipper() { System.out.println("Clidder"); }
}
public class Clidlets extends Clidders {
public void flipper() {
System.out.println("Flip a Clidlet");
super.flipper();
}
public static void main(String [] args) {
new Clidlets().flipper();
}
}
What is the result?
A:Flip a Clidlet
B:Flip a Clidder
C:Flip a Clidder
Flip a Clidlet
D:Flip a Clidlet
Flip a Clidder
E:Compilation fails.
答案:E
第16题 (2.0分) 题号:949 难度:中 第4章
给定下面的类定义
class Base{
public void amethod(){
System.out.println("Base");
}
}
public class Hay extends Base{
public static void main(String argv[]){
Hay h = new Hay();
h.amethod();
}
}
下面在类Hay 中的哪一个方法将会编译并使程序打印出字符串"Hay"?
A:public int amethod(){ System.out.println("Hay");}
B:public void amethod(long l){ System.out.println("Hay");}
C:public void amethod(){ System.out.println("Hay");}
D:public void amethod(void){ System.out.println("Hay");}
答案:C
第17题 (2.0分) 题号:950 难度:中 第4章
假设你被给予如下设计
"一个人有姓名,年龄,地址和性别。你将要设计一个类来表示一类叫做病人的人。这种人
可以被给予诊断,有配偶并且可能活着"。假设表示人的类已经创建了,当你设计病人类时
如下哪些应该被包含在内?
A:registration date
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 is true? (Choose all that apply.)
A:"X extends Y" is correct if and only if X is a class and Y is an interface.
B:"X extends Y" is correct if and only if X is an interface and Y is a class.
C:"X extends Y" is correct if X and Y are either both classes or both interfaces.
D:"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
答案:C
第20题 (2.0分) 题号:443 难度:中 第5章
下列哪些属于Java的数据类型
A:接口
B:无符号整数类型
C:整数类型
D:浮点数类型
答案:ACD
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:445 难度:中 第1章
下列哪些是Java语言中的保留字
A:if
B:sizeof
C:private
D:null
答案:ACD
第2题 (2.0分) 题号:1063 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void 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 all right answer:
A:prints 12,34 and 56
B:prints 24,68and 112
C:prints 10,28and 46
D:compilation error
答案:D
第3题 (2.0分) 题号:1061 难度:中 第1章
给定下面的类定义
public class Upton{
public static void main(String argv[]){
}
public void amethod(int i){}
//Here
}
下面哪一个在替换//Here 后是合法的?
A:public int amethod(int z){}
B:public int amethod(int i,int j){return 99;}
C:protected void amethod(long l){ }
D:private void anothermethod(){}
答案:BCD
第4题 (2.0分) 题号:1058 难度:中 第1章
what is the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第5题 (2.0分) 题号:1054 难度:中 第2章
What is the result when you compile and run the following code?
public class Example {
public static void 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 all right 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 appears in the standard output when the method named testing is invoked?
class Example{
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 all right 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 the result when you compile and run the following code
pubic class Example{
public static void main(String[] args){
boolean flag=true;
if(flag=true) {System.out.println("true");}
else
{System.out.println("false");
}
}
}
A:true is printed to standard out
B:false is printed to standard out
C:An exception is raised
D:Nothing happens
答案:A
第8题 (2.0分) 题号:1001 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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 numbers 1 and 2 to the standard output
B:the numbers 3 to the standard output
C:this method writes the number 0 to the standard output
D:the numbers 4 to the standard output
E:the numbers 5 through 9 to the standard output
F:the code does 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 the result 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 all right answer:
A:10 10
B:10 null
C:0 0
D:compilation error
E:An exception in hai
F:an excepton in hello
答案:F
第11题 (2.0分) 题号:969 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{
Integer b=new Integer(10);
new Example().Add(b);
System.out.println(b.intValue());
}
public void Add(Integer b)
{
int i=b.intValue();
i+=3;
b=new Integer(i);
}
}
Select all right answer?
A:will print 10;
B:will print 13;
C:compilation Error in Line 4,implicit conversion to Integer to String is not possible
D:Exception in line 10
答案:A
第12题 (2.0分) 题号:953 难度:中 第4章
Given:
class Top {
public Top(String s) { System.out.print("B"); }
}
public class Bottom2 extends Top {
public Bottom2(String s) { System.out.print("D"); }
public static void main(String [] args) {
new Bottom2("C");
System.out.println(" ");
} }
What is the result?
A:BD
B:DB
C:BDC
D:DBC
E:Compilation fails
答案:E
第13题 (2.0分) 题号:954 难度:中 第4章
Given:
class Clidder {
private final void flipper() { System.out.println("Clidder"); }
}
public class Clidlet extends Clidder {
public final void flipper() { System.out.println("Clidlet"); }
public static void main(String [] args) {
new Clidlet().flipper();
} }
What is the result?
A:Clidlet
B:Clidder
C:Clidder
Clidlet
D:Clidlet
Clidder
E:Compilation fails.
答案:A
第14题 (2.0分) 题号:961 难度:中 第4章
Given the following,
1. class X { void do1() { } }
2. class Y extends X { void do2() { } }
3.
4. class Chrome {
5. public static void main(String [] args) {
6. X x1 = new X();
7. X x2 = new Y();
8. Y y1 = new Y();
9. // insert code here
10. }
11. }
Which, inserted at line 9, will compile?
A:x2.do2();
B:(Y)x2.do2();
C:((Y)x2).do2();
D:None of the above statements will compile.
答案:C
第15题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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:String s[5]=new String[] {"Zero","One","Two","Three","Four"};
C:String s[]=new String[] {"Zero","One","Two","Three","Four"};
D:String s[]=new String[]={"Zero","One","Two","Three","Four"};
答案:C
第17题 (2.0分) 题号:1113 难度:中 第6章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ String elements[]={"for","tea","too"};
String first=(elements.length>0)?elements[0]:null;
System.out.println(first);
}
}
Select all right answer:
A:compilation fails;
B:an exception thrown at runtime
C:prints:null
D:prints:for
答案:D
第18题 (2.0分) 题号:1125 难度:中 第7章
Given the following code?
public class AccountManager{
private Map accountTotals = new HashMap();
private int retiremantFund;
public int getBalance(String accountName){
Integer total = (Integer)accountTotals.get(accountName);
if(total == null)
total = Integer.valueOf(0);
return total.intValue();
}
public void setBalance(String accountName, int amount){
accountTotals.put(accountName, Integer.valueOf(amount));
}
}
This class is to be updated to make use of appropriate generic types, with
no changes in behavior(for better or worse). Which of these steps could be performed?
Select all right answer:
A:Replace line 2 with
private Map<String, int> accountTotals = new HashMap<String , int >();
B:Replace line 2 with
private Map<String, Integer> accountTotals = new HashMap<String , Integer >();
C:Replace line 2 with
private Map<String<Integer>> accountTotals = new HashMap<String<Integer>>();
D:Replace line 5-8 with
int total = accountTotals.get(accountName);
if (total == null)
total = 0;
return total;
E:Replace line 5-8 with
Integer total = accountTotals.get(accountName);
if (total == null)
total = 0;
return total;
F:Replace line 5-8 with
return accountTotals.get(accountName);
答案:BEF
第19题 (2.0分) 题号:1144 难度:中 第8章
what String instance method would return true when invoked like this
a.method(b);
where a="GROUNDhog" and b="groundHOG"
select all answers
A:equals()
B:toLowercase()
C:toUppercase()
D:equalsIgnoreCase()
E:None of the above
答案:D
第20题 (2.0分) 题号:1133 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{int b=10;
method(i);
}
static void method(int k)
{ System.out.println("primitive type call");
}
static void method(Integer k)
{ System.out.println("wrapper type call");
}
}
Select all right answer?
A:wrapper type call
B:primitive type call
C:Compiler error
D:compiles fine ,throws runtime exception
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:921 难度:中 第1章
下列哪项是Java语言中所规定的注释样式?
A://单行注释
B:--单行注释
C:/*
*单行或多行注释
*/
D:/**
*文档注释
*/
答案:ACD
第2题 (2.0分) 题号:1066 难度:中 第1章
what is the result when you compile and run the following code?
import java.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 all right answer:
A:compile error ,attempting to perform binary comparison on logical data type
B:Compilation and output of "we are equal 10"
C:compilation and output of "not equal 20"
D:compilation and output of "not equal 10"
答案:D
第3题 (2.0分) 题号:1067 难度:中 第1章
Given:
1. class Maybe {
2. public static 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 are true?
A:Line 5 produces true.
B:Line 5 produces false.
C:Line 6 produces true.
D:Line 6 produces false.
E:Line 7 produces true.
F:Line 7 produces 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:short a,b,c;
答案:B
第5题 (2.0分) 题号:1005 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:Compile error at line 4
答案:A
第6题 (2.0分) 题号:1052 难度:中 第2章
What is the result when you compile and run the following code?
public class Example {
public static void main(String args[]){
for(int i=0; i <= 10; i++) {
if(i > 6){break;}
}
System.out.println(i);
}
}
select all right answer:
A:6
B:7
C:10
D:11
E:Compilation fails
F:An exception 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章
class Example{
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 of x will cause case 3 printed in the output
A:less than zero
B:less 4
C:between 4 and 9
D:10 and greater
E:None
答案:B
第9题 (2.0分) 题号:1002 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:compiation error
C:runtime exception
答案:B
第10题 (2.0分) 题号:965 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int x=12;
public void method(int x)
{
x+=x;
System.out.println(x);
}
public static void main(String [] args)
{
Example t=new Exaple();
t.method(5);
}
}
What is the output from the example class?
Select all right answer?
A:5
B:10
C:12
D:17
E:24
答案:B
第11题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第12题 (2.0分) 题号:952 难度:中 第4章
Given:
class Clidders {
public final void flipper() { System.out.println("Clidder"); }
}
public class Clidlets extends Clidders {
public void flipper() {
System.out.println("Flip a Clidlet");
super.flipper();
}
public static void main(String [] args) {
new Clidlets().flipper();
}
}
What is the result?
A:Flip a Clidlet
B:Flip a Clidder
C:Flip a Clidder
Flip a Clidlet
D:Flip a Clidlet
Flip a Clidder
E:Compilation fails.
答案:E
第13题 (2.0分) 题号:942 难度:中 第4章
当你试着编译运行下面的类的时候,可能会发生什么?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(String argv[]){
Severn s = new Severn();
}
void Severn(){
System.out.println("Severn");
}
}
A:Compilation and output of the string "Severn" at runtime
B:Compile time error
C:Compilation and no output at runtime
D:Compilation and output of the string "Base"
答案:B
第14题 (2.0分) 题号:951 难度:中 第4章
当你试图编译并运行如下代码时会发生什么?
class Base {
int i = 99;
public void amethod () {
System.out.println ("Base.amethod ()");
}
Base () {
amethod ();
}
}
public class RType extends Base {
int i = -1;
public static void main (String argv []) {
Base b = new RType ();
System.out.println (b.i);
b.amethod ();
}
public void amethod () {
System.out.println ("RType.amethod ()");
}
}
A:RType.amethod
-1
RType.amethod
B:RType.amethod
99
RType.amethod
C:99
RType.amethod
D:Compile time error
答案:B
第15题 (2.0分) 题号:937 难度:中 第5章
Which declare a compilable abstract class? (Choose all that apply.)
A:public abstract class Canine { public Bark speak(); }
B:public abstract class Canine { public Bark speak() { } }
C:public class Canine { public abstract Bark speak(); }
D:public class Canine abstract { public abstract Bark speak(); }
答案:B
第16题 (2.0分) 题号:913 难度:中 第6章
你想用下面的代码查找数组最后一个元素的值,当你编译并运行它的时候,会发
生什么?
public class MyAr{
public static void main(String argv[]){
int[] i = new int[5];
System.out.println(i[5]);
}
}
A:Compilation and output of 0
B:Compilation and output of null
C:Compilation and runtime Exception
D:Compile time error
答案:C
第17题 (2.0分) 题号:1117 难度:中 第6章
what is the result when you compile and run the following code?
Boolean [] b1=new Boolean[10];
boolean[] b2=new Boolean[10];
System.out.println("the value of b1[1]="+b1[1]);
System.out.println("the value of b2[1]="+b2[1]);
A:prints the valueof b1[1]=false; the value of b2[1]=false
B:prints the valueof b1[1]=null; the value of b2[1]=null
C:prints the valueof b1[1]=null; the value of b2[1]=false
D:prints the valueof b1[1]=false; the value of b2[1]=null
答案:C
第18题 (2.0分) 题号:1121 难度:中 第7章
A programmer has an algorithm that requires a java.util.List that provides
an efficient implementation of add() , but does NOT need to support quick
random access?
Select all right answers:
A:java.util.Queue
B:java.util.ArrayList
C:java.util.LinearSet
D:java.util.LinkedList
答案:D
第19题 (2.0分) 题号:1149 难度:中 第8章
class Example{
public static void main(String[] args){
String str="Welcome";
str.concat("To java");
System.out.println(str);
}
}
what will be printed out?
A:the String is immutable,Compilation Errors at line 3
B:the String is immutable,Run Exception at line 3
C:Prints "Welcome"
D:prints "Welcome To java"
答案:C
第20题 (2.0分) 题号:1151 难度:中 第8章
what is the result when you compile and run the following code?
String s="hello";
String t="hello";
char c[]={'h','e','l','l','o'};
Which will return true?select all right answers:
A:s.equals(t)
B:t.equals(c)
C:s==t
D:t.equals(new String ("hello"))
E:t==c
答案:ACD
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1060 难度:中 第1章
假设有如下类定义,如下哪些方法可以合法放置在"//Here"的注释之后?
public class Rid {
public void amethod (int i, String s) {}
// Here
}
A:public void amethod (String s, int i) {}
B:public int amethod (int i, String s) {}
C:public void amethod (int i, String mystring) {}
D:public void Amethod (int i, String s) {}
答案:AD
第2题 (2.0分) 题号:442 难度:中 第1章
what is the result 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 all right answer:
A:a compiler error
B:a running error
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 the result when you compile and run the following code?
pubic class Example{
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 range of 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 the result when you compile and run the following code?
pubic class Example{
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 is printed
B:Compile time error
C:the value 100,100,100 printed
D:only 100 printed
答案:C
第7题 (2.0分) 题号:988 难度:中 第2章
what is the result 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 is printed out
B:The value 3 is printed out
C:The value 3 and 4 are printed out
D:The value 1,3 and 4 are printed out
答案:C
第8题 (2.0分) 题号:1003 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
public static void main(String[] args){
new Example().add(5);
}
public void add(int a){
loop:for(int i=1;i<3;i++){
for(int j=1;j<3;j++){
if(a==5) {break loop;}
}
}
}
}
A:create a runtime error
B:Throw an ArrayIndexOutofBoundsException
C:print values 1,2,2,4
D:Produces no output
答案:D
第9题 (2.0分) 题号:1053 难度:中 第2章
2、 What is the result when you compile and run the following code?
public class Example {
public static void main(String args[]){
int x = 12;
while(x < 10) {x--; }
System.out.print(x);
}
}
select all right answer:
A:prints 0
B:prints 10
C:prints 12
D:Line 5 will never be reached
答案:C
第10题 (2.0分) 题号:966 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public static void main(String [] args)
{
Example a=new Example();
a.method();
}
public void amehtod ()
{ System.out.println(j);
System.out.println(b);
}
}
Select all right answer?
A:compilation succeeds and at run time on output of 0 and false
B:compilation succeds and at run time an output of 0 and true
C:compile time error b is not initialised
D:compile time error z must be assigned a char value
答案:A
第11题 (2.0分) 题号:977 难度:中 第3章
what is the result when you compil and run the following code?
class Example
{
static int myArg=1;
public static void main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select all right answer:
A:this code compiles and displays 0 in the statndard output when run
B:this code compiles and displays 1 in the statndard output when run
C:this code does not compile because you can't define a local variable names the same as static variable
D:this code doesn'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 static void main(String[] args) {
final Fizz f1 = new Fizz();
Fizz f2 = new Fizz();
Fizz f3 = FizzSwitch(f1,f2);
System.out.println((f1 == f3) + " " + (f1.x == f3.x));
}
static Fizz FizzSwitch(Fizz x, Fizz y) {
final Fizz z = x;
z.x = 6;
return z;
} }
What is the result?
A:true true
B:true false
C:false true
D:false false
E:Compilation fails.
F:An exception is thrown at runtime.
答案:A
第13题 (2.0分) 题号:962 难度:中 第4章
what is the result when you compile and run the following code?
class Example
{
static final long tooth=343L;
static long doIt(long tooth)
{
System.out.println(++tooth+" ");
return ++tooth;
}
public static void main(String [] args)
{ System.out.println(tooth+" ");
final long tooth=340L;
new Example().doIt(tooth);
System.out.println(tooth);
}
}
Select all right answer:
A:343 340 340
B:343 340 342
C:343 341 342
D:343 341 343
E:343 341 340
F:compilation fails
答案:E
第14题 (2.0分) 题号:945 难度:中 第4章
假设有如下类定义
class Mammal {
Mammal () {
System.out.println ("Mamml");
}
}
class Dog extends Mammal {
Dog () {
System.out.println ("Dog");
}
}
public class Collie extends Dog {
public static void main (String argv []) {
Collie c = new Collie ();
}
Collie () {
this ("Good Dog");
System.out.println ("Collie");
}
Collie (String s) {
System.out.println (s);
}
}
将会输出什么?
A:Compile time 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{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class is not declared as abstract.
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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 are legal 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 =new int[3][3];
B:int[] i =new int[3][3];
C:int[][] i =new int[3][3];
D:int i[3][3]=new int[][];
答案:C
第18题 (2.0分) 题号:1126 难度:中 第7章
What is the result when you compile and run the following code?
import java.util.*;
public class Example {
private String s;
public Example(String s){
this.s = s;
}
public static void main (String[] args) {
HashSet<Object> hs = new HashSet<Object>();
Example ws1 = new Example("aard");
Example ws2 = new Example("aard");
String s1 = new String("aard");
String s2 = new String("aard");
hs.add(ws1);
hs.add(ws2);
hs.add(s1);
hs.add(s2);
System.out.println(hs.size());
}
}
Select all right answer:
A:0
B:1
C:2
D:3
E:4
F:Compilation fails
答案:D
第19题 (2.0分) 题号:1154 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{ public void myBuf(StringBuffer s,StringBuffer s1)
{
s.append("how are you");
s=s1;
}
public static void main(String [] args)
{
Example tb=new Example();
StringBuffer s=new StringBuffer("hello');
StringBuffer s1=new StringBuffer("doing');
tb.myBuf(s,s1);
System.out.println(s);
}
}
Select all right answer?
A:hello how are you
B:hello
C:hello how are you doing
D:compile time error
答案:A
第20题 (2.0分) 题号:1148 难度:中 第8章
class Example{
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:Compilation Errors says the String is immutable
B:ABFDE
C:ABCDE
D:ABCD
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1058 难度:中 第1章
what is the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第2题 (2.0分) 题号:922 难度:中 第1章
现有如下五个声明:
Linel: int a_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 class Upton{
public static void main(String argv[]){
}
public void amethod(int i){}
//Here
}
下面哪一个在替换//Here 后是合法的?
A:public int amethod(int z){}
B:public int amethod(int i,int j){return 99;}
C:protected void amethod(long l){ }
D:private void anothermethod(){}
答案:BCD
第4题 (2.0分) 题号:440 难度:中 第1章
which results is true when you compile and run the following code?
boolean b1=true; boolean b2=false
Select all right answer:
A:b1==b2
B:b1||b2
C:b1|&b2
D:b1&&b2
答案:A
第5题 (2.0分) 题号:996 难度:中 第2章
class Example{
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 the above will allow compilation to succeed
答案:C
第6题 (2.0分) 题号:1000 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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 a runtime error
B:produce a compile time error
C:Print out "Total0"
D:Generate the following as output
i=0 j=10
i=1 j=9
i=2 j=8
答案:C
第7题 (2.0分) 题号:997 难度:中 第2章
what is the result when you compile and run the following code
class Example{
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 code placed after the comment //For loop would populate the elements of the array ia[] with values of the variable i?
public class Example{
public static void main(String argv[]){
Example l=new Example();
l.amethod();
}
public void amethod(){
int ia[]=new int[4];
//Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
A:for(int i=0;i<ia.length()-1;i++)
B:for(int i=0;i<ia.length();i++)
C:for(int i=1;i<4;i++)
D:for(int i=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 class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
void Crowle(){
System.out.println("Greetings from Crowle");
}
}
A:Compilation and output of the string "Greetings from Crowle"
B:Compile time error, constructors may not have a return type
C:Compilation and output of string "void"
D:Compilation and no output at runtime
答案:D
第11题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:public protected amethod(int i)
B:public void amethod(int i)
C:public void amethod(void)
D:void public amethod(int i)
答案:B
第12题 (2.0分) 题号:956 难度:中 第4章
Given:
1. class Zing {
2. protected Hmpf h;
3. }
4. class Woop extends Zing { }
5. class Hmpf { }
Which is true? (Choose all that apply.)
A:Woop is-a Hmpf and has-a Zing.
B:Zing is-a Woop and has-a Hmpf.
C:Hmpf has-a Woop and Woop is-a Zing.
D:Woop has-a Hmpf and Woop is-a Zing.
E:Zing has-a Hmpf and Zing is-a Woop.
答案:D
第13题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle b1 = new Beagle();
7. Dog dog1 = new Dog();
8. Dog dog2 = b1;
9. // insert code 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 the above statements will compile
答案:AB
第14题 (2.0分) 题号:946 难度:中 第4章
下面哪些论述是正确的?
A:Constructors are not inherited
B:Constructors can be overridden
C:A parental constructor can be invoked using this
D:Any method may contain a call to this or super
答案:A
第15题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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 the result when you compile and run the following code?
Boolean [] b1=new Boolean[10];
boolean[] b2=new Boolean[10];
System.out.println("the value of b1[1]="+b1[1]);
System.out.println("the value of b2[1]="+b2[1]);
A:prints the valueof b1[1]=false; the value of b2[1]=false
B:prints the valueof b1[1]=null; the value of b2[1]=null
C:prints the valueof b1[1]=null; the value of b2[1]=false
D:prints the valueof b1[1]=false; the value of b2[1]=null
答案:C
第17题 (2.0分) 题号:1116 难度:中 第6章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ int anar[]=new int[5];
System.out.println(anar[0]);
}
}
Select all right answer?
A:Error: anar is referenced before it is initialized
B:Null
C:0
D:5
答案:C
第18题 (2.0分) 题号:1124 难度:中 第7章
Given the following code?
import java.util.*;
class Example{
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);
}
}
Which statements could be inserted at //insert declarations here to allow the code to compile and run?
Select all right 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 of above.
答案:B
第19题 (2.0分) 题号:1143 难度:中 第8章
class Polish {
public static void main(String[] args) {
int x = 4;
StringBuffer sb = 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 the result?
A:.faza
B:.fzba
C:..azba
D:..fezba
E:Compilation fails.
答案:C
第20题 (2.0分) 题号:1152 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{
public static void change(String str, char ch[])
{
Str="changed";
Ch[0]='C';
}
public static void main(String [] args)
{
String str=new String("world');
char ch[]={'H' ,'e'.,'l','l','o'};
change(str, ch);
System.out.println(str+"and"+new String(ch));
}
}
Select all right answer?
A:world and hello
B:world and Cello
C:changed and hello
D:changed and Cello
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1055 难度:中 第1章
which of the following lines of code will compile without error?
A:int i=0;
if (i) System.out.println("Hi");
B:boolean b=true;
boolean b2=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:short a,b,c;
答案:B
第3题 (2.0分) 题号:1059 难度:中 第1章
Which are valid declarations?
A:int $x;
B:int 123;
C:int _123;
D:int %percent;
E:int *divide;
F:int central_sales_region_Summer_2005_gross_sales;
答案:ACF
第4题 (2.0分) 题号:1064 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ byte B=10;
byte D=12;
byte I=B*D;
}
}
Select all right answer:
A:the code will compile and run
B:compile time error while declaring variable
C:compile time error while multiplication
D:none of the above
答案:C
第5题 (2.0分) 题号:988 难度:中 第2章
what is the result 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 is printed out
B:The value 3 is printed out
C:The value 3 and 4 are printed out
D:The value 1,3 and 4 are printed out
答案:C
第6题 (2.0分) 题号:989 难度:中 第2章
class Example{
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 of x will cause case 3 printed in the output
A:less than zero
B:less 4
C:between 4 and 9
D:10 and greater
E:None
答案:B
第7题 (2.0分) 题号:930 难度:中 第2章
现有:
1.class Output (
2.public static void main (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 the result when you compile and run the following code?
class Example{
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:compiation error
C:runtime exception
答案:B
第10题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第11题 (2.0分) 题号:966 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public static void main(String [] args)
{
Example a=new Example();
a.method();
}
public void amehtod ()
{ System.out.println(j);
System.out.println(b);
}
}
Select all right answer?
A:compilation succeeds and at run time on output of 0 and false
B:compilation succeds and at run time an output of 0 and true
C:compile time error b is not initialised
D:compile time error z must be assigned a char value
答案:A
第12题 (2.0分) 题号:955 难度:中 第4章
Given:
1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
A:Flower getType() { return this; }
B:String getType() { return "this"; }
C:Plant getType() { return this; }
D:Tulip getType() { return new Tulip(); }
答案:ACD
第13题 (2.0分) 题号:941 难度:中 第4章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}
}
A:Compile time error indicating that a class with any final methods must be declared final itself
B:Compile time error indicating that you cannot inherit from a class with final methods
C:Run time error indicating that Base is not defined as final
D:Success in compilation and output of "amethod" at run time.
答案:D
第14题 (2.0分) 题号:954 难度:中 第4章
Given:
class Clidder {
private final void flipper() { System.out.println("Clidder"); }
}
public class Clidlet extends Clidder {
public final void flipper() { System.out.println("Clidlet"); }
public static void main(String [] args) {
new Clidlet().flipper();
} }
What is the result?
A:Clidlet
B:Clidder
C:Clidder
Clidlet
D:Clidlet
Clidder
E:Compilation fails.
答案:A
第15题 (2.0分) 题号:449 难度:中 第5章
关于接口的说法中正确的是
A:接口所有的方法都是抽象的
B:接口所有的方法一定都是public属性的
C:用于定义接口的关键字是implements
D:接口是Java中特殊类,包含常量和抽象方法
答案:ABD
第16题 (2.0分) 题号:1112 难度:中 第6章
Which are legal 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 are legal declarations? Select all right answer?
class Example
{
public static void main(String [] args)
{ String s[]=new String[6];
System.out.println(s[6]);
}
}
Select all right answer?
A:a null is printed
B:compile time error
C:exception is thrown
D:null followed by 0 is printed on the screen
答案:C
第18题 (2.0分) 题号:1123 难度:中 第7章
Which is the result when you compile and run the following code?
class Example{
public static void main(String[] args){
Vector a = new Vector();
a.add (10);
System.out.println(a.get(0));
}
}
Select all right answers:
A:Prints 10
B:Prints 11
C:Compilations error
答案:A
第19题 (2.0分) 题号:1139 难度:中 第8章
Given:
class Hexy {
public static void main(String[] args) {
Integer i = 42;
String s = (i<40)?"life":(i>50)?"universe":"everything";
System.out.println(s);
}
}
What is the result?
A:null
B:life
C:universe
D:everything
E:Compilation fails.
F:An exception is thrown at runtime.
答案:D
第20题 (2.0分) 题号:1136 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{
public static void main(String []args)
{
Short s=new Short("5");
Boolean b;
// insert code here
}
}
Which,inserted independently at //insert code here?,will compile?
Select all right answer:
A:b=(Number instanceof s);
B:b=(s instanceof Short);
C:b=s instanceof (Short);
D:b=(s instanceof Number);
E:b= s instanceof (Object);
F:b=(s instanceof String);
答案:BD
第1题 (2.0分) 题号:1059 难度:中 第1章
Which are valid declarations?
A:int $x;
B:int 123;
C:int _123;
D:int %percent;
E:int *divide;
F:int central_sales_region_Summer_2005_gross_sales;
答案:ACF
第2题 (2.0分) 题号:1058 难度:中 第1章
what is the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第3题 (2.0分) 题号:1062 难度:中 第1章
给定下面的类定义
public class ShrubHill{
public void foregate(String sName){}
//Here
}
下面的哪一个方法可以合法的直接替换//Here?
A:public int foregate(String sName){}
B:public void foregate(StringBuffer sName){}
C:public void foreGate(String sName){}
D:private void foregate(String sType){}
答案:BC
第4题 (2.0分) 题号:989 难度:中 第2章
class Example{
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 of x will cause case 3 printed in the output
A:less than zero
B:less 4
C:between 4 and 9
D:10 and greater
E:None
答案:B
第5题 (2.0分) 题号:984 难度:中 第2章
what is the result when you compile and run the following code?
pubic class Example{
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 range of 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 the value of j when printed
class Example{
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:Compile error
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 you change the break statement below so that it breaks out of the inner
and middle loops and continues with the next iteration of the outer loop?
class Example{
public static void main(String[] args){
outer:for(int x=0;x<3;x++){
middle: for(int y=0;y<3;y++){
inner:for(int z=0;z<3;z++){
break;
}
}
}
}
}
A:break inner;
B:break outer;
C:break middle;
D:continue
E:continue middle
答案:C
第9题 (2.0分) 题号:968 难度:中 第3章
what is the result when you compile and run the following code?
class Use{public int i=10;}
class Example
{
public static void main(String [] args)
{
Example o=new Example();
o.amethod();
}
public void amethod()
{
int i=99;
Use v=new Use();
v.i=30;
another(v, i);
System.out.println (a.i);
}
public void another(User v,int i)
{
i=0;
v.i=20;
Use vh=new Use();
v=vh;
System.out.println (v.i+" "+i+" ");
}
Select all right answer?
A:10 0 30
B:10 0 20
C:20 0 30
D:20 99 30
答案:B
第10题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:public protected amethod(int i)
B:public void amethod(int i)
C:public void amethod(void)
D:void public amethod(int i)
答案:B
第11题 (2.0分) 题号:976 难度:中 第3章
你如何在类中实现封装?
A:make all variables protected and only allow access via methods
B:make all variables private and only allow access via methods
C:ensure all variables are represented by wrapper classes
D:ensure all variables are accessed through methods in an ancestor class
答案:B
第12题 (2.0分) 题号:977 难度:中 第3章
what is the result when you compil and run the following code?
class Example
{
static int myArg=1;
public static void main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select all right answer:
A:this code compiles and displays 0 in the statndard output when run
B:this code compiles and displays 1 in the statndard output when run
C:this code does not compile because you can't define a local variable names the same as static variable
D:this code doesn't compile because the local vriable is used before it is initialized
答案:D
第13题 (2.0分) 题号:953 难度:中 第4章
Given:
class Top {
public Top(String s) { System.out.print("B"); }
}
public class Bottom2 extends Top {
public Bottom2(String s) { System.out.print("D"); }
public static void main(String [] args) {
new Bottom2("C");
System.out.println(" ");
} }
What is the result?
A:BD
B:DB
C:BDC
D:DBC
E:Compilation fails
答案:E
第14题 (2.0分) 题号:941 难度:中 第4章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}
}
A:Compile time error indicating that a class with any final methods must be declared final itself
B:Compile time error indicating that you cannot inherit from a class with final methods
C:Run time error indicating that Base is not defined as final
D:Success in compilation and output of "amethod" at run time.
答案:D
第15题 (2.0分) 题号:955 难度:中 第4章
Given:
1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
A:Flower getType() { return this; }
B:String getType() { return "this"; }
C:Plant getType() { return this; }
D:Tulip getType() { return new Tulip(); }
答案:ACD
第16题 (2.0分) 题号:945 难度:中 第4章
假设有如下类定义
class Mammal {
Mammal () {
System.out.println ("Mamml");
}
}
class Dog extends Mammal {
Dog () {
System.out.println ("Dog");
}
}
public class Collie extends Dog {
public static void main (String argv []) {
Collie c = new Collie ();
}
Collie () {
this ("Good Dog");
System.out.println ("Collie");
}
Collie (String s) {
System.out.println (s);
}
}
将会输出什么?
A:Compile time error
B:Mammal, Dog, Good Dog, Collie
C:Good Dog, Collie, Dog, Mammal
D:Good Dog, Collie
答案:B
第17题 (2.0分) 题号:961 难度:中 第4章
Given the following,
1. class X { void do1() { } }
2. class Y extends X { void do2() { } }
3.
4. class Chrome {
5. public static void main(String [] args) {
6. X x1 = new X();
7. X x2 = new Y();
8. Y y1 = new Y();
9. // insert code here
10. }
11. }
Which, inserted at line 9, will compile?
A:x2.do2();
B:(Y)x2.do2();
C:((Y)x2).do2();
D:None of the above statements will compile.
答案:C
第18题 (2.0分) 题号:938 难度:中 第5章
Which is true? (Choose all that apply.)
A:"X extends Y" is correct if and only if X is a class and Y is an interface.
B:"X extends Y" is correct if and only if X is an interface and Y is a class.
C:"X extends Y" is correct if X and Y are either both classes or both interfaces.
D:"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
答案:C
第19题 (2.0分) 题号:936 难度:中 第5章
Given the following,
1. interface Base {
2. boolean m1 ();
3. byte m2(short s);
4. }
Which code fragments will compile? (Choose all that apply.)
A:interface Base2 implements Base { }
B:abstract class Class2 extends Base {
public boolean m1() { return true; } }
C:abstract class Class2 implements Base { }
D:abstract class Class2 implements Base {
public boolean m1() { return (true); } }
E:class Class2 implements Base {
boolean m1() { return false; }
byte m2(short s) { return 42; } }
答案:CD
第20题 (2.0分) 题号:964 难度:中 第5章
Select the two statements that best indicate a situation with low coupling.
A:The attributes of the class are all private.
B:The class refers to a small number of other objects.
C:The object contains only a small number of variables.
D:The object is referred to using an anonymous variable, not directly.
E:The reference variable is declared for an interface type, not a class. The interface provides a small number of methods.
F:It is unlikely that changes made to one class will require any changes in another.
答案:EF
二、多选 共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:short a,b,c;
答案:B
第3题 (2.0分) 题号:921 难度:中 第1章
下列哪项是Java语言中所规定的注释样式?
A://单行注释
B:--单行注释
C:/*
*单行或多行注释
*/
D:/**
*文档注释
*/
答案:ACD
第4题 (2.0分) 题号:992 难度:中 第2章
what is the result when you compile and run the following code
class Example{
public static void main(String[] args){
int i=1
switch(i){
case 0:System.out.println("zero"); break;
case 1:System.out.println("one");
case 2: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章
class Example{
public static void main(String[] args){
int t=0;
while(1)
{ if(t++<10) break;
}
}
}
what will be the value of t after the while loop?
A:9
B:10
C:11
D:Compilation Error
E:An Exception will occurs
答案:D
第6题 (2.0分) 题号:1005 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:Compile error 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 the result 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 all right answer:
A:10 10
B:10 null
C:0 0
D:compilation error
E:An exception in hai
F:an excepton in hello
答案:F
第10题 (2.0分) 题号:974 难度:中 第3章
当你试着编译运行下面的两个放在同一个目录的文件的时候,可能会发生什么?
//File P1.java
package MyPackage;
class P1{
void afancymethod(){
System.out.println("What a fancy method");
}
}
//File P2.java
public class P2 extends P1{
afancymethod();
}
A:Both compile and P2 outputs "What a fancy method" when run
B:Neither will compile
C:Both compile but P2 has an error at run time
D:P1 compiles cleanly but P2 has an error at compile time
答案:D
第11题 (2.0分) 题号:972 难度:中 第3章
给定下面的类
public class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
Crowle(){
System.out.println("Greetings from Crowle");
}
}
构造方法会返回哪一种数据类型?
A:null
B:integer
C:String
D:no datatype is returned
答案:D
第12题 (2.0分) 题号:965 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int x=12;
public void method(int x)
{
x+=x;
System.out.println(x);
}
public static void main(String [] args)
{
Example t=new Exaple();
t.method(5);
}
}
What is the output from the example class?
Select all right answer?
A:5
B:10
C:12
D:17
E:24
答案:B
第13题 (2.0分) 题号:949 难度:中 第4章
给定下面的类定义
class Base{
public void amethod(){
System.out.println("Base");
}
}
public class Hay extends Base{
public static void main(String argv[]){
Hay h = new Hay();
h.amethod();
}
}
下面在类Hay 中的哪一个方法将会编译并使程序打印出字符串"Hay"?
A:public int amethod(){ System.out.println("Hay");}
B:public void amethod(long l){ System.out.println("Hay");}
C:public void amethod(){ System.out.println("Hay");}
D:public void amethod(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 Minor extends Uber {
Minor() { super(y); y = y + 3; }
public static void main(String [] args) {
new Minor();
System.out.println(y);
} }
What is the result?
A:6
B:7
C:8
D:9
E:Compilation fails.
F:An exception is thrown.
答案:D
第15题 (2.0分) 题号:943 难度:中 第4章
下面的哪一句陈述是正确的?
A:The default constructor has a return type of void
B:The default constructor takes a parameter of void
C:The default constructor takes no parameters
D:The default constructor is not created if the class has any constructors of its own.
答案:CD
第16题 (2.0分) 题号:952 难度:中 第4章
Given:
class Clidders {
public final void flipper() { System.out.println("Clidder"); }
}
public class Clidlets extends Clidders {
public void flipper() {
System.out.println("Flip a Clidlet");
super.flipper();
}
public static void main(String [] args) {
new Clidlets().flipper();
}
}
What is the result?
A:Flip a Clidlet
B:Flip a Clidder
C:Flip a Clidder
Flip a Clidlet
D:Flip a Clidlet
Flip a Clidder
E:Compilation fails.
答案:E
第17题 (2.0分) 题号:950 难度:中 第4章
假设你被给予如下设计
"一个人有姓名,年龄,地址和性别。你将要设计一个类来表示一类叫做病人的人。这种人
可以被给予诊断,有配偶并且可能活着"。假设表示人的类已经创建了,当你设计病人类时
如下哪些应该被包含在内?
A:registration date
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 declare a compilable abstract class? (Choose all that apply.)
A:public abstract class Canine { public Bark speak(); }
B:public abstract class Canine { public Bark speak() { } }
C:public class Canine { public abstract Bark speak(); }
D:public class Canine abstract { public abstract Bark speak(); }
答案:B
第20题 (2.0分) 题号:939 难度:中 第5章
public abstract interface Frobnicate { public void twiddle(String s); }
Which is a correct class? (Choose all that apply.)
A:public abstract class Frob implements Frobnicate {
public abstract void twiddle(String s) { }
}
B:public abstract class Frob implements Frobnicate { }
C:public class Frob extends Frobnicate {
public void twiddle(Integer i) { }
}
D:public class Frob implements Frobnicate {
public void twiddle(Integer i) { }
}
E:public class Frob implements Frobnicate {
public void twiddle(String i) { }
public void twiddle(Integer s) { }
}
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1064 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ byte B=10;
byte D=12;
byte I=B*D;
}
}
Select all right answer:
A:the code will compile and run
B:compile time error while declaring variable
C:compile time error while multiplication
D:none of the above
答案:C
第2题 (2.0分) 题号:445 难度:中 第1章
下列哪些是Java语言中的保留字
A:if
B:sizeof
C:private
D:null
答案:ACD
第3题 (2.0分) 题号:1063 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void 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 all right answer:
A:prints 12,34 and 56
B:prints 24,68and 112
C:prints 10,28and 46
D:compilation error
答案:D
第4题 (2.0分) 题号:996 难度:中 第2章
class Example{
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 the above 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 the result when you compile and run the following code?
public class Example {
public static void 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 range of value x would produce of output "Test 2"?
select all right answer:
A:x < 4
B:x > 4
C:x > 9
D:None
答案:D
第7题 (2.0分) 题号:990 难度:中 第2章
what is the result when 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 of these
答案:B
第8题 (2.0分) 题号:447 难度:中 第2章
下列哪些属于Java语言的流程控制语句
A:赋值语句
B:分支语句
C:跳转语句
D:循环语句
答案:BCD
第9题 (2.0分) 题号:978 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static int i;
public static void main(String [] args)
{
System.out.println(i);
}
}
Select all right answer:
A:0
B:1
C:null
D:Error variable I may not have been initialized
答案:A
第10题 (2.0分) 题号:981 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=20;
static {int i=10;}
public static void main(String [] args)
{
Example a=new Example();
System.out.println(a.i);
}
}
Select all right answer?
A:prints 10
B:prints 20
C:compilation , variable "i" declared twice
D:compilation error, static initializers for initialization purpose only
答案:B
第11题 (2.0分) 题号:973 难度:中 第3章
当你试着编译运行下面的代码的时候,可能会发生什么?
public class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
void Crowle(){
System.out.println("Greetings from Crowle");
}
}
A:Compilation and output of the string "Greetings from Crowle"
B:Compile time error, constructors may not have a return type
C:Compilation and output of string "void"
D:Compilation and no output at runtime
答案:D
第12题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第13题 (2.0分) 题号:947 难度:中 第4章
试图编译并运行下面代码会发生什么?
class Base {
public void amethod (int i, String s) {
System.out.println ("Base amethod");
}
Base () {
System.out.println ("Base Constructor");
}
}
public class Child extends Base {
int i;
String Parm = "Hello";
public static void main (String argv []) {
Child c = new Child ():
c.amethod ():
}
void amethod (int i, String Parm) {
super.amethod (i, Parm);
}
public void amethod () {}
}
A:Compile time error
B:Error caused by illegal syntax super.amethod (i, Parm)
C:Output of "Base Constructor"
D:Error caused by incorrect parameter names in call to super.amethod
答案:A
第14题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle b1 = new Beagle();
7. Dog dog1 = new Dog();
8. Dog dog2 = b1;
9. // insert code 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 the above statements will compile
答案:AB
第15题 (2.0分) 题号:940 难度:中 第4章
给定下面的类定义
class Base{
Base(int i){}
}
class DefCon extends Base{
DefCon(int i){
//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 static void main(String[] args) {
final Fizz f1 = new Fizz();
Fizz f2 = new Fizz();
Fizz f3 = FizzSwitch(f1,f2);
System.out.println((f1 == f3) + " " + (f1.x == f3.x));
}
static Fizz FizzSwitch(Fizz x, Fizz y) {
final Fizz z = x;
z.x = 6;
return z;
} }
What is the result?
A:true true
B:true false
C:false true
D:false false
E:Compilation fails.
F:An exception is thrown at runtime.
答案:A
第17题 (2.0分) 题号:946 难度:中 第4章
下面哪些论述是正确的?
A:Constructors are not inherited
B:Constructors can be overridden
C:A parental constructor can be invoked using this
D:Any method may 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{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class is not declared as abstract.
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler will complain that the method myfunc in the base class has no body, nobody at all to love it
答案:A
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1066 难度:中 第1章
what is the result when you compile and run the following code?
import java.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 all right answer:
A:compile error ,attempting to perform binary comparison on logical data type
B:Compilation and output of "we are equal 10"
C:compilation and output of "not equal 20"
D:compilation and 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 the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第4题 (2.0分) 题号:1050 难度:中 第2章
What appears in the standard output when the method named testing is invoked?
class Example{
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 all right 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 the result when you compile and run the following code?
class Example{
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:Compile error 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 class Example{
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 value of m would cause "default" to be the output?
A:0
B:1
C:2
D:3
答案:CD
第8题 (2.0分) 题号:985 难度:中 第2章
pubic class Example{
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 the following questions are definitely true?
A:this switch block is illegal,because only integers can be used in the switch statement
B:this switch block is fine
C:this switch block is illegal,because the default statement must come last
D:when this codes runs,nothing is written to the standard output
E:When this codes runs,the letter "a" is written to the standard output
答案:BE
第9题 (2.0分) 题号:966 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public static void main(String [] args)
{
Example a=new Example();
a.method();
}
public void amehtod ()
{ System.out.println(j);
System.out.println(b);
}
}
Select all right answer?
A:compilation succeeds and at run time on output of 0 and false
B:compilation succeds and at run time an output of 0 and true
C:compile time error b is not initialised
D:compile time error z must be assigned a char value
答案:A
第10题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:public protected amethod(int i)
B:public void amethod(int i)
C:public void amethod(void)
D:void public amethod(int i)
答案:B
第11题 (2.0分) 题号:980 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{ void fun()
{
static int i=0;
}
public static void main(String [] args)
{ Example obj=new Example();
obj.fun();
obj.fun();
}
}
Select all right answer:
A:1
B:2
C:compilation error
D:run time error
答案:C
第12题 (2.0分) 题号:977 难度:中 第3章
what is the result when you compil and run the following code?
class Example
{
static int myArg=1;
public static void main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select all right answer:
A:this code compiles and displays 0 in the statndard output when run
B:this code compiles and displays 1 in the statndard output when run
C:this code does not compile because you can't define a local variable names the same as static variable
D:this code doesn't compile because the local vriable is used before it is initialized
答案:D
第13题 (2.0分) 题号:951 难度:中 第4章
当你试图编译并运行如下代码时会发生什么?
class Base {
int i = 99;
public void amethod () {
System.out.println ("Base.amethod ()");
}
Base () {
amethod ();
}
}
public class RType extends Base {
int i = -1;
public static void main (String argv []) {
Base b = new RType ();
System.out.println (b.i);
b.amethod ();
}
public void amethod () {
System.out.println ("RType.amethod ()");
}
}
A:RType.amethod
-1
RType.amethod
B:RType.amethod
99
RType.amethod
C:99
RType.amethod
D:Compile time error
答案:B
第14题 (2.0分) 题号:943 难度:中 第4章
下面的哪一句陈述是正确的?
A:The default constructor has a return type of void
B:The default constructor takes a parameter of void
C:The default constructor takes no parameters
D:The default constructor 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 Dog extends Mammal {
Dog () {
System.out.println ("Dog");
}
}
public class Collie extends Dog {
public static void main (String argv []) {
Collie c = new Collie ();
}
Collie () {
this ("Good Dog");
System.out.println ("Collie");
}
Collie (String s) {
System.out.println (s);
}
}
将会输出什么?
A:Compile time 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. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
A:Flower getType() { return this; }
B:String getType() { return "this"; }
C:Plant getType() { return this; }
D:Tulip getType() { return new Tulip(); }
答案:ACD
第17题 (2.0分) 题号:942 难度:中 第4章
当你试着编译运行下面的类的时候,可能会发生什么?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(String argv[]){
Severn s = new Severn();
}
void Severn(){
System.out.println("Severn");
}
}
A:Compilation and output of the string "Severn" at runtime
B:Compile time error
C:Compilation and no output at runtime
D:Compilation and output of the string "Base"
答案:B
第18题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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 the following,
1. interface Base {
2. boolean m1 ();
3. byte m2(short s);
4. }
Which code fragments will compile? (Choose all that apply.)
A:interface Base2 implements Base { }
B:abstract class Class2 extends Base {
public boolean m1() { return true; } }
C:abstract class Class2 implements Base { }
D:abstract class Class2 implements Base {
public boolean m1() { return (true); } }
E:class Class2 implements Base {
boolean m1() { return false; }
byte m2(short s) { return 42; } }
答案:CD
第20题 (2.0分) 题号:935 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class is not declared as abstract.
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler will complain that the method myfunc in the base class has no body, nobody at all to love it
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:919 难度:中 第1章
下列哪项是int类型的字面量?
A:\u03A6
B:077
C:0xABBC
D:-20
答案:BCD
第2题 (2.0分) 题号:441 难度:中 第1章
what is the result 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 all right answer:
A:1,1
B:1,2
C:2,1
D:2,2
答案:C
第3题 (2.0分) 题号:1057 难度:中 第1章
what is the result 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 all right answer:
A:9 foo 47 86 foo
B:9 foo 47 4244foo
C:72 foo 47 4244 foo
D:72foo 425 86 foo
E:72 foo 425 4244 foo
F:compilation fails
答案:D
第4题 (2.0分) 题号:995 难度:中 第2章
How can you change the break statement below so that it breaks out of the inner
and middle loops and continues with the next iteration of the outer loop?
class Example{
public static void main(String[] args){
outer:for(int x=0;x<3;x++){
middle: for(int y=0;y<3;y++){
inner:for(int z=0;z<3;z++){
break;
}
}
}
}
}
A:break inner;
B:break outer;
C:break middle;
D:continue
E:continue middle
答案:C
第5题 (2.0分) 题号:1002 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:compiation error
C:runtime exception
答案: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 the result when you compile and run the following code
class Example{
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 all variables protected and only allow access via methods
B:make all variables private and only allow access via methods
C:ensure all variables are represented by wrapper classes
D:ensure all variables are accessed through methods in an ancestor class
答案:B
第10题 (2.0分) 题号:969 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{
Integer b=new Integer(10);
new Example().Add(b);
System.out.println(b.intValue());
}
public void Add(Integer b)
{
int i=b.intValue();
i+=3;
b=new Integer(i);
}
}
Select all right answer?
A:will print 10;
B:will print 13;
C:compilation Error in Line 4,implicit conversion to Integer to String is not possible
D:Exception in line 10
答案:A
第11题 (2.0分) 题号:972 难度:中 第3章
给定下面的类
public class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
Crowle(){
System.out.println("Greetings from Crowle");
}
}
构造方法会返回哪一种数据类型?
A:null
B:integer
C:String
D:no datatype is returned
答案:D
第12题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第13题 (2.0分) 题号:940 难度:中 第4章
给定下面的类定义
class Base{
Base(int i){}
}
class DefCon extends Base{
DefCon(int i){
//XX
}
}
如果将标记//XX 的地方替换为下面的行,哪一行是独立合法的?
A:super();
B:this();
C:this(99);
D:super(99);
答案:D
第14题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle b1 = new Beagle();
7. Dog dog1 = new Dog();
8. Dog dog2 = b1;
9. // insert code 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 the above statements will compile
答案:AB
第15题 (2.0分) 题号:952 难度:中 第4章
Given:
class Clidders {
public final void flipper() { System.out.println("Clidder"); }
}
public class Clidlets extends Clidders {
public void flipper() {
System.out.println("Flip a Clidlet");
super.flipper();
}
public static void main(String [] args) {
new Clidlets().flipper();
}
}
What is the result?
A:Flip a Clidlet
B:Flip a Clidder
C:Flip a Clidder
Flip a Clidlet
D:Flip a Clidlet
Flip a Clidder
E:Compilation fails.
答案:E
第16题 (2.0分) 题号:949 难度:中 第4章
给定下面的类定义
class Base{
public void amethod(){
System.out.println("Base");
}
}
public class Hay extends Base{
public static void main(String argv[]){
Hay h = new Hay();
h.amethod();
}
}
下面在类Hay 中的哪一个方法将会编译并使程序打印出字符串"Hay"?
A:public int amethod(){ System.out.println("Hay");}
B:public void amethod(long l){ System.out.println("Hay");}
C:public void amethod(){ System.out.println("Hay");}
D:public void amethod(void){ System.out.println("Hay");}
答案:C
第17题 (2.0分) 题号:950 难度:中 第4章
假设你被给予如下设计
"一个人有姓名,年龄,地址和性别。你将要设计一个类来表示一类叫做病人的人。这种人
可以被给予诊断,有配偶并且可能活着"。假设表示人的类已经创建了,当你设计病人类时
如下哪些应该被包含在内?
A:registration date
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 is true? (Choose all that apply.)
A:"X extends Y" is correct if and only if X is a class and Y is an interface.
B:"X extends Y" is correct if and only if X is an interface and Y is a class.
C:"X extends Y" is correct if X and Y are either both classes or both interfaces.
D:"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces.
答案:C
第20题 (2.0分) 题号:443 难度:中 第5章
下列哪些属于Java的数据类型
A:接口
B:无符号整数类型
C:整数类型
D:浮点数类型
答案:ACD
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:445 难度:中 第1章
下列哪些是Java语言中的保留字
A:if
B:sizeof
C:private
D:null
答案:ACD
第2题 (2.0分) 题号:1063 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void 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 all right answer:
A:prints 12,34 and 56
B:prints 24,68and 112
C:prints 10,28and 46
D:compilation error
答案:D
第3题 (2.0分) 题号:1061 难度:中 第1章
给定下面的类定义
public class Upton{
public static void main(String argv[]){
}
public void amethod(int i){}
//Here
}
下面哪一个在替换//Here 后是合法的?
A:public int amethod(int z){}
B:public int amethod(int i,int j){return 99;}
C:protected void amethod(long l){ }
D:private void anothermethod(){}
答案:BCD
第4题 (2.0分) 题号:1058 难度:中 第1章
what is the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第5题 (2.0分) 题号:1054 难度:中 第2章
What is the result when you compile and run the following code?
public class Example {
public static void 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 all right 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 appears in the standard output when the method named testing is invoked?
class Example{
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 all right 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 the result when you compile and run the following code
pubic class Example{
public static void main(String[] args){
boolean flag=true;
if(flag=true) {System.out.println("true");}
else
{System.out.println("false");
}
}
}
A:true is printed to standard out
B:false is printed to standard out
C:An exception is raised
D:Nothing happens
答案:A
第8题 (2.0分) 题号:1001 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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 numbers 1 and 2 to the standard output
B:the numbers 3 to the standard output
C:this method writes the number 0 to the standard output
D:the numbers 4 to the standard output
E:the numbers 5 through 9 to the standard output
F:the code does 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 the result 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 all right answer:
A:10 10
B:10 null
C:0 0
D:compilation error
E:An exception in hai
F:an excepton in hello
答案:F
第11题 (2.0分) 题号:969 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{
Integer b=new Integer(10);
new Example().Add(b);
System.out.println(b.intValue());
}
public void Add(Integer b)
{
int i=b.intValue();
i+=3;
b=new Integer(i);
}
}
Select all right answer?
A:will print 10;
B:will print 13;
C:compilation Error in Line 4,implicit conversion to Integer to String is not possible
D:Exception in line 10
答案:A
第12题 (2.0分) 题号:953 难度:中 第4章
Given:
class Top {
public Top(String s) { System.out.print("B"); }
}
public class Bottom2 extends Top {
public Bottom2(String s) { System.out.print("D"); }
public static void main(String [] args) {
new Bottom2("C");
System.out.println(" ");
} }
What is the result?
A:BD
B:DB
C:BDC
D:DBC
E:Compilation fails
答案:E
第13题 (2.0分) 题号:954 难度:中 第4章
Given:
class Clidder {
private final void flipper() { System.out.println("Clidder"); }
}
public class Clidlet extends Clidder {
public final void flipper() { System.out.println("Clidlet"); }
public static void main(String [] args) {
new Clidlet().flipper();
} }
What is the result?
A:Clidlet
B:Clidder
C:Clidder
Clidlet
D:Clidlet
Clidder
E:Compilation fails.
答案:A
第14题 (2.0分) 题号:961 难度:中 第4章
Given the following,
1. class X { void do1() { } }
2. class Y extends X { void do2() { } }
3.
4. class Chrome {
5. public static void main(String [] args) {
6. X x1 = new X();
7. X x2 = new Y();
8. Y y1 = new Y();
9. // insert code here
10. }
11. }
Which, inserted at line 9, will compile?
A:x2.do2();
B:(Y)x2.do2();
C:((Y)x2).do2();
D:None of the above statements will compile.
答案:C
第15题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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:String s[5]=new String[] {"Zero","One","Two","Three","Four"};
C:String s[]=new String[] {"Zero","One","Two","Three","Four"};
D:String s[]=new String[]={"Zero","One","Two","Three","Four"};
答案:C
第17题 (2.0分) 题号:1113 难度:中 第6章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ String elements[]={"for","tea","too"};
String first=(elements.length>0)?elements[0]:null;
System.out.println(first);
}
}
Select all right answer:
A:compilation fails;
B:an exception thrown at runtime
C:prints:null
D:prints:for
答案:D
第18题 (2.0分) 题号:1125 难度:中 第7章
Given the following code?
public class AccountManager{
private Map accountTotals = new HashMap();
private int retiremantFund;
public int getBalance(String accountName){
Integer total = (Integer)accountTotals.get(accountName);
if(total == null)
total = Integer.valueOf(0);
return total.intValue();
}
public void setBalance(String accountName, int amount){
accountTotals.put(accountName, Integer.valueOf(amount));
}
}
This class is to be updated to make use of appropriate generic types, with
no changes in behavior(for better or worse). Which of these steps could be performed?
Select all right answer:
A:Replace line 2 with
private Map<String, int> accountTotals = new HashMap<String , int >();
B:Replace line 2 with
private Map<String, Integer> accountTotals = new HashMap<String , Integer >();
C:Replace line 2 with
private Map<String<Integer>> accountTotals = new HashMap<String<Integer>>();
D:Replace line 5-8 with
int total = accountTotals.get(accountName);
if (total == null)
total = 0;
return total;
E:Replace line 5-8 with
Integer total = accountTotals.get(accountName);
if (total == null)
total = 0;
return total;
F:Replace line 5-8 with
return accountTotals.get(accountName);
答案:BEF
第19题 (2.0分) 题号:1144 难度:中 第8章
what String instance method would return true when invoked like this
a.method(b);
where a="GROUNDhog" and b="groundHOG"
select all answers
A:equals()
B:toLowercase()
C:toUppercase()
D:equalsIgnoreCase()
E:None of the above
答案:D
第20题 (2.0分) 题号:1133 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{int b=10;
method(i);
}
static void method(int k)
{ System.out.println("primitive type call");
}
static void method(Integer k)
{ System.out.println("wrapper type call");
}
}
Select all right answer?
A:wrapper type call
B:primitive type call
C:Compiler error
D:compiles fine ,throws runtime exception
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:921 难度:中 第1章
下列哪项是Java语言中所规定的注释样式?
A://单行注释
B:--单行注释
C:/*
*单行或多行注释
*/
D:/**
*文档注释
*/
答案:ACD
第2题 (2.0分) 题号:1066 难度:中 第1章
what is the result when you compile and run the following code?
import java.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 all right answer:
A:compile error ,attempting to perform binary comparison on logical data type
B:Compilation and output of "we are equal 10"
C:compilation and output of "not equal 20"
D:compilation and output of "not equal 10"
答案:D
第3题 (2.0分) 题号:1067 难度:中 第1章
Given:
1. class Maybe {
2. public static 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 are true?
A:Line 5 produces true.
B:Line 5 produces false.
C:Line 6 produces true.
D:Line 6 produces false.
E:Line 7 produces true.
F:Line 7 produces 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:short a,b,c;
答案:B
第5题 (2.0分) 题号:1005 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:Compile error at line 4
答案:A
第6题 (2.0分) 题号:1052 难度:中 第2章
What is the result when you compile and run the following code?
public class Example {
public static void main(String args[]){
for(int i=0; i <= 10; i++) {
if(i > 6){break;}
}
System.out.println(i);
}
}
select all right answer:
A:6
B:7
C:10
D:11
E:Compilation fails
F:An exception 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章
class Example{
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 of x will cause case 3 printed in the output
A:less than zero
B:less 4
C:between 4 and 9
D:10 and greater
E:None
答案:B
第9题 (2.0分) 题号:1002 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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:compiation error
C:runtime exception
答案:B
第10题 (2.0分) 题号:965 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int x=12;
public void method(int x)
{
x+=x;
System.out.println(x);
}
public static void main(String [] args)
{
Example t=new Exaple();
t.method(5);
}
}
What is the output from the example class?
Select all right answer?
A:5
B:10
C:12
D:17
E:24
答案:B
第11题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第12题 (2.0分) 题号:952 难度:中 第4章
Given:
class Clidders {
public final void flipper() { System.out.println("Clidder"); }
}
public class Clidlets extends Clidders {
public void flipper() {
System.out.println("Flip a Clidlet");
super.flipper();
}
public static void main(String [] args) {
new Clidlets().flipper();
}
}
What is the result?
A:Flip a Clidlet
B:Flip a Clidder
C:Flip a Clidder
Flip a Clidlet
D:Flip a Clidlet
Flip a Clidder
E:Compilation fails.
答案:E
第13题 (2.0分) 题号:942 难度:中 第4章
当你试着编译运行下面的类的时候,可能会发生什么?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(String argv[]){
Severn s = new Severn();
}
void Severn(){
System.out.println("Severn");
}
}
A:Compilation and output of the string "Severn" at runtime
B:Compile time error
C:Compilation and no output at runtime
D:Compilation and output of the string "Base"
答案:B
第14题 (2.0分) 题号:951 难度:中 第4章
当你试图编译并运行如下代码时会发生什么?
class Base {
int i = 99;
public void amethod () {
System.out.println ("Base.amethod ()");
}
Base () {
amethod ();
}
}
public class RType extends Base {
int i = -1;
public static void main (String argv []) {
Base b = new RType ();
System.out.println (b.i);
b.amethod ();
}
public void amethod () {
System.out.println ("RType.amethod ()");
}
}
A:RType.amethod
-1
RType.amethod
B:RType.amethod
99
RType.amethod
C:99
RType.amethod
D:Compile time error
答案:B
第15题 (2.0分) 题号:937 难度:中 第5章
Which declare a compilable abstract class? (Choose all that apply.)
A:public abstract class Canine { public Bark speak(); }
B:public abstract class Canine { public Bark speak() { } }
C:public class Canine { public abstract Bark speak(); }
D:public class Canine abstract { public abstract Bark speak(); }
答案:B
第16题 (2.0分) 题号:913 难度:中 第6章
你想用下面的代码查找数组最后一个元素的值,当你编译并运行它的时候,会发
生什么?
public class MyAr{
public static void main(String argv[]){
int[] i = new int[5];
System.out.println(i[5]);
}
}
A:Compilation and output of 0
B:Compilation and output of null
C:Compilation and runtime Exception
D:Compile time error
答案:C
第17题 (2.0分) 题号:1117 难度:中 第6章
what is the result when you compile and run the following code?
Boolean [] b1=new Boolean[10];
boolean[] b2=new Boolean[10];
System.out.println("the value of b1[1]="+b1[1]);
System.out.println("the value of b2[1]="+b2[1]);
A:prints the valueof b1[1]=false; the value of b2[1]=false
B:prints the valueof b1[1]=null; the value of b2[1]=null
C:prints the valueof b1[1]=null; the value of b2[1]=false
D:prints the valueof b1[1]=false; the value of b2[1]=null
答案:C
第18题 (2.0分) 题号:1121 难度:中 第7章
A programmer has an algorithm that requires a java.util.List that provides
an efficient implementation of add() , but does NOT need to support quick
random access?
Select all right answers:
A:java.util.Queue
B:java.util.ArrayList
C:java.util.LinearSet
D:java.util.LinkedList
答案:D
第19题 (2.0分) 题号:1149 难度:中 第8章
class Example{
public static void main(String[] args){
String str="Welcome";
str.concat("To java");
System.out.println(str);
}
}
what will be printed out?
A:the String is immutable,Compilation Errors at line 3
B:the String is immutable,Run Exception at line 3
C:Prints "Welcome"
D:prints "Welcome To java"
答案:C
第20题 (2.0分) 题号:1151 难度:中 第8章
what is the result when you compile and run the following code?
String s="hello";
String t="hello";
char c[]={'h','e','l','l','o'};
Which will return true?select all right answers:
A:s.equals(t)
B:t.equals(c)
C:s==t
D:t.equals(new String ("hello"))
E:t==c
答案:ACD
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1060 难度:中 第1章
假设有如下类定义,如下哪些方法可以合法放置在"//Here"的注释之后?
public class Rid {
public void amethod (int i, String s) {}
// Here
}
A:public void amethod (String s, int i) {}
B:public int amethod (int i, String s) {}
C:public void amethod (int i, String mystring) {}
D:public void Amethod (int i, String s) {}
答案:AD
第2题 (2.0分) 题号:442 难度:中 第1章
what is the result 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 all right answer:
A:a compiler error
B:a running error
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 the result when you compile and run the following code?
pubic class Example{
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 range of 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 the result when you compile and run the following code?
pubic class Example{
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 is printed
B:Compile time error
C:the value 100,100,100 printed
D:only 100 printed
答案:C
第7题 (2.0分) 题号:988 难度:中 第2章
what is the result 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 is printed out
B:The value 3 is printed out
C:The value 3 and 4 are printed out
D:The value 1,3 and 4 are printed out
答案:C
第8题 (2.0分) 题号:1003 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
public static void main(String[] args){
new Example().add(5);
}
public void add(int a){
loop:for(int i=1;i<3;i++){
for(int j=1;j<3;j++){
if(a==5) {break loop;}
}
}
}
}
A:create a runtime error
B:Throw an ArrayIndexOutofBoundsException
C:print values 1,2,2,4
D:Produces no output
答案:D
第9题 (2.0分) 题号:1053 难度:中 第2章
2、 What is the result when you compile and run the following code?
public class Example {
public static void main(String args[]){
int x = 12;
while(x < 10) {x--; }
System.out.print(x);
}
}
select all right answer:
A:prints 0
B:prints 10
C:prints 12
D:Line 5 will never be reached
答案:C
第10题 (2.0分) 题号:966 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public static void main(String [] args)
{
Example a=new Example();
a.method();
}
public void amehtod ()
{ System.out.println(j);
System.out.println(b);
}
}
Select all right answer?
A:compilation succeeds and at run time on output of 0 and false
B:compilation succeds and at run time an output of 0 and true
C:compile time error b is not initialised
D:compile time error z must be assigned a char value
答案:A
第11题 (2.0分) 题号:977 难度:中 第3章
what is the result when you compil and run the following code?
class Example
{
static int myArg=1;
public static void main(String [] args)
{
int myArg;
System.out.println(myArg);
}
}
Select all right answer:
A:this code compiles and displays 0 in the statndard output when run
B:this code compiles and displays 1 in the statndard output when run
C:this code does not compile because you can't define a local variable names the same as static variable
D:this code doesn'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 static void main(String[] args) {
final Fizz f1 = new Fizz();
Fizz f2 = new Fizz();
Fizz f3 = FizzSwitch(f1,f2);
System.out.println((f1 == f3) + " " + (f1.x == f3.x));
}
static Fizz FizzSwitch(Fizz x, Fizz y) {
final Fizz z = x;
z.x = 6;
return z;
} }
What is the result?
A:true true
B:true false
C:false true
D:false false
E:Compilation fails.
F:An exception is thrown at runtime.
答案:A
第13题 (2.0分) 题号:962 难度:中 第4章
what is the result when you compile and run the following code?
class Example
{
static final long tooth=343L;
static long doIt(long tooth)
{
System.out.println(++tooth+" ");
return ++tooth;
}
public static void main(String [] args)
{ System.out.println(tooth+" ");
final long tooth=340L;
new Example().doIt(tooth);
System.out.println(tooth);
}
}
Select all right answer:
A:343 340 340
B:343 340 342
C:343 341 342
D:343 341 343
E:343 341 340
F:compilation fails
答案:E
第14题 (2.0分) 题号:945 难度:中 第4章
假设有如下类定义
class Mammal {
Mammal () {
System.out.println ("Mamml");
}
}
class Dog extends Mammal {
Dog () {
System.out.println ("Dog");
}
}
public class Collie extends Dog {
public static void main (String argv []) {
Collie c = new Collie ();
}
Collie () {
this ("Good Dog");
System.out.println ("Collie");
}
Collie (String s) {
System.out.println (s);
}
}
将会输出什么?
A:Compile time 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{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class is not declared as abstract.
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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 are legal 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 =new int[3][3];
B:int[] i =new int[3][3];
C:int[][] i =new int[3][3];
D:int i[3][3]=new int[][];
答案:C
第18题 (2.0分) 题号:1126 难度:中 第7章
What is the result when you compile and run the following code?
import java.util.*;
public class Example {
private String s;
public Example(String s){
this.s = s;
}
public static void main (String[] args) {
HashSet<Object> hs = new HashSet<Object>();
Example ws1 = new Example("aard");
Example ws2 = new Example("aard");
String s1 = new String("aard");
String s2 = new String("aard");
hs.add(ws1);
hs.add(ws2);
hs.add(s1);
hs.add(s2);
System.out.println(hs.size());
}
}
Select all right answer:
A:0
B:1
C:2
D:3
E:4
F:Compilation fails
答案:D
第19题 (2.0分) 题号:1154 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{ public void myBuf(StringBuffer s,StringBuffer s1)
{
s.append("how are you");
s=s1;
}
public static void main(String [] args)
{
Example tb=new Example();
StringBuffer s=new StringBuffer("hello');
StringBuffer s1=new StringBuffer("doing');
tb.myBuf(s,s1);
System.out.println(s);
}
}
Select all right answer?
A:hello how are you
B:hello
C:hello how are you doing
D:compile time error
答案:A
第20题 (2.0分) 题号:1148 难度:中 第8章
class Example{
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:Compilation Errors says the String is immutable
B:ABFDE
C:ABCDE
D:ABCD
答案:D
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1058 难度:中 第1章
what is the result when you compile and run the following code?
char c='c';
int i=10;
double d=10;
long l=1;
String s="Hello"
Select all right answer:
A:c=c+i
B:s+=i
C:i+=s
D:c+s
答案:B
第2题 (2.0分) 题号:922 难度:中 第1章
现有如下五个声明:
Linel: int a_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 class Upton{
public static void main(String argv[]){
}
public void amethod(int i){}
//Here
}
下面哪一个在替换//Here 后是合法的?
A:public int amethod(int z){}
B:public int amethod(int i,int j){return 99;}
C:protected void amethod(long l){ }
D:private void anothermethod(){}
答案:BCD
第4题 (2.0分) 题号:440 难度:中 第1章
which results is true when you compile and run the following code?
boolean b1=true; boolean b2=false
Select all right answer:
A:b1==b2
B:b1||b2
C:b1|&b2
D:b1&&b2
答案:A
第5题 (2.0分) 题号:996 难度:中 第2章
class Example{
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 the above will allow compilation to succeed
答案:C
第6题 (2.0分) 题号:1000 难度:中 第2章
what is the result when you compile and run the following code?
class Example{
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 a runtime error
B:produce a compile time error
C:Print out "Total0"
D:Generate the following as output
i=0 j=10
i=1 j=9
i=2 j=8
答案:C
第7题 (2.0分) 题号:997 难度:中 第2章
what is the result when you compile and run the following code
class Example{
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 code placed after the comment //For loop would populate the elements of the array ia[] with values of the variable i?
public class Example{
public static void main(String argv[]){
Example l=new Example();
l.amethod();
}
public void amethod(){
int ia[]=new int[4];
//Start For loop
{
ia[i]=i;
System.out.println(ia[i]);
}
}
A:for(int i=0;i<ia.length()-1;i++)
B:for(int i=0;i<ia.length();i++)
C:for(int i=1;i<4;i++)
D:for(int i=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 class Crowle{
public static void main(String argv[]){
Crowle c = new Crowle();
}
void Crowle(){
System.out.println("Greetings from Crowle");
}
}
A:Compilation and output of the string "Greetings from Crowle"
B:Compile time error, constructors may not have a return type
C:Compilation and output of string "void"
D:Compilation and no output at runtime
答案:D
第11题 (2.0分) 题号:975 难度:中 第3章
下面的哪一个声明是合法的?
A:public protected amethod(int i)
B:public void amethod(int i)
C:public void amethod(void)
D:void public amethod(int i)
答案:B
第12题 (2.0分) 题号:956 难度:中 第4章
Given:
1. class Zing {
2. protected Hmpf h;
3. }
4. class Woop extends Zing { }
5. class Hmpf { }
Which is true? (Choose all that apply.)
A:Woop is-a Hmpf and has-a Zing.
B:Zing is-a Woop and has-a Hmpf.
C:Hmpf has-a Woop and Woop is-a Zing.
D:Woop has-a Hmpf and Woop is-a Zing.
E:Zing has-a Hmpf and Zing is-a Woop.
答案:D
第13题 (2.0分) 题号:960 难度:中 第4章
Given:
1. class Dog { }
2. class Beagle extends Dog { }
3.
4. class Kennel {
5. public static void main(String [] arfs) {
6. Beagle b1 = new Beagle();
7. Dog dog1 = new Dog();
8. Dog dog2 = b1;
9. // insert code 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 the above statements will compile
答案:AB
第14题 (2.0分) 题号:946 难度:中 第4章
下面哪些论述是正确的?
A:Constructors are not inherited
B:Constructors can be overridden
C:A parental constructor can be invoked using this
D:Any method may contain a call to this or super
答案:A
第15题 (2.0分) 题号:934 难度:中 第5章
当你试着编译运行下面的代码的时候,可能会发生什么?
abstract class Base{
abstract public void myfunc();
public void another(){
System.out.println("Another method");
}
}
public class Abs extends Base{
public static void main(String argv[]){
Abs a = new Abs();
a.amethod();
}
public void myfunc(){
System.out.println("My func");
}
public void amethod(){
myfunc();
}
}
A:The code will compile and run, printing out the words "My Func"
B:The compiler will complain that the Base class has non abstract methods
C:The code will compile but complain at run time that the Base class has non abstract methods
D:The compiler 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 the result when you compile and run the following code?
Boolean [] b1=new Boolean[10];
boolean[] b2=new Boolean[10];
System.out.println("the value of b1[1]="+b1[1]);
System.out.println("the value of b2[1]="+b2[1]);
A:prints the valueof b1[1]=false; the value of b2[1]=false
B:prints the valueof b1[1]=null; the value of b2[1]=null
C:prints the valueof b1[1]=null; the value of b2[1]=false
D:prints the valueof b1[1]=false; the value of b2[1]=null
答案:C
第17题 (2.0分) 题号:1116 难度:中 第6章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ int anar[]=new int[5];
System.out.println(anar[0]);
}
}
Select all right answer?
A:Error: anar is referenced before it is initialized
B:Null
C:0
D:5
答案:C
第18题 (2.0分) 题号:1124 难度:中 第7章
Given the following code?
import java.util.*;
class Example{
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);
}
}
Which statements could be inserted at //insert declarations here to allow the code to compile and run?
Select all right 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 of above.
答案:B
第19题 (2.0分) 题号:1143 难度:中 第8章
class Polish {
public static void main(String[] args) {
int x = 4;
StringBuffer sb = 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 the result?
A:.faza
B:.fzba
C:..azba
D:..fezba
E:Compilation fails.
答案:C
第20题 (2.0分) 题号:1152 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{
public static void change(String str, char ch[])
{
Str="changed";
Ch[0]='C';
}
public static void main(String [] args)
{
String str=new String("world');
char ch[]={'H' ,'e'.,'l','l','o'};
change(str, ch);
System.out.println(str+"and"+new String(ch));
}
}
Select all right answer?
A:world and hello
B:world and Cello
C:changed and hello
D:changed and Cello
答案:B
二、多选 共20题 (共计40分)
第1题 (2.0分) 题号:1055 难度:中 第1章
which of the following lines of code will compile without error?
A:int i=0;
if (i) System.out.println("Hi");
B:boolean b=true;
boolean b2=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:short a,b,c;
答案:B
第3题 (2.0分) 题号:1059 难度:中 第1章
Which are valid declarations?
A:int $x;
B:int 123;
C:int _123;
D:int %percent;
E:int *divide;
F:int central_sales_region_Summer_2005_gross_sales;
答案:ACF
第4题 (2.0分) 题号:1064 难度:中 第1章
what is the result when you compile and run the following code?
class Example
{
public static void main(String [] args)
{ byte B=10;
byte D=12;
byte I=B*D;
}
}
Select all right answer:
A:the code will compile and run
B:compile time error while declaring variable
C:compile time error while multiplication
D:none of the above
答案:C
第5题 (2.0分) 题号:988 难度:中 第2章
what is the result 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 is printed out
B:The value 3 is printed out
C:The value 3 and 4 are printed out
D:The value 1,3 and 4 are printed out
答案:C
第6题 (2.0分) 题号:989 难度:中 第2章
class Example{
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 of x will cause case 3 printed in the output
A:less than zero
B:less 4
C:between 4 and 9
D:10 and greater
E:None
答案:B
第7题 (2.0分) 题号:930 难度:中 第2章
现有:
1.class Output (
2.public static void main (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 the result when you compile and run the following code?
class Example{
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:compiation error
C:runtime exception
答案:B
第10题 (2.0分) 题号:979 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
static boolean Paddy;
public static void main(String [] args)
{
System.out.println(Paddy);
}
}
Select all right answer:
A:compile time error;
B:compilation and output of false;
C:compilation and output of true
D:compilation and output of null
答案:B
第11题 (2.0分) 题号:966 难度:中 第3章
what is the result when you compile and run the following code?
class Example
{
int i=10;
int j;
char z=l;
boolean b;
public static void main(String [] args)
{
Example a=new Example();
a.method();
}
public void amehtod ()
{ System.out.println(j);
System.out.println(b);
}
}
Select all right answer?
A:compilation succeeds and at run time on output of 0 and false
B:compilation succeds and at run time an output of 0 and true
C:compile time error b is not initialised
D:compile time error z must be assigned a char value
答案:A
第12题 (2.0分) 题号:955 难度:中 第4章
Given:
1. class Plant {
2. String getName() { return "plant"; }
3. Plant getType() { return this; }
4. }
5. class Flower extends Plant {
6. // insert code here
7. }
8. class Tulip extends Flower { }
Which statement(s), inserted at line 6, will compile? (Choose all that apply.)
A:Flower getType() { return this; }
B:String getType() { return "this"; }
C:Plant getType() { return this; }
D:Tulip getType() { return new Tulip(); }
答案:ACD
第13题 (2.0分) 题号:941 难度:中 第4章
当你试着编译运行下面的代码的时候,可能会发生什么?
class Base{
public final void amethod(){
System.out.println("amethod");
}
}
public class Fin extends Base{
public static void main(String argv[]){
Base b = new Base();
b.amethod();
}
}
A:Compile time error indicating that a class with any final methods must be declared final itself
B:Compile time error indicating that you cannot inherit from a class with final methods
C:Run time error indicating that Base is not defined as final
D:Success in compilation and output of "amethod" at run time.
答案:D
第14题 (2.0分) 题号:954 难度:中 第4章
Given:
class Clidder {
private final void flipper() { System.out.println("Clidder"); }
}
public class Clidlet extends Clidder {
public final void flipper() { System.out.println("Clidlet"); }
public static void main(String [] args) {
new Clidlet().flipper();
} }
What is the result?
A:Clidlet
B:Clidder
C:Clidder
Clidlet
D:Clidlet
Clidder
E:Compilation fails.
答案:A
第15题 (2.0分) 题号:449 难度:中 第5章
关于接口的说法中正确的是
A:接口所有的方法都是抽象的
B:接口所有的方法一定都是public属性的
C:用于定义接口的关键字是implements
D:接口是Java中特殊类,包含常量和抽象方法
答案:ABD
第16题 (2.0分) 题号:1112 难度:中 第6章
Which are legal 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 are legal declarations? Select all right answer?
class Example
{
public static void main(String [] args)
{ String s[]=new String[6];
System.out.println(s[6]);
}
}
Select all right answer?
A:a null is printed
B:compile time error
C:exception is thrown
D:null followed by 0 is printed on the screen
答案:C
第18题 (2.0分) 题号:1123 难度:中 第7章
Which is the result when you compile and run the following code?
class Example{
public static void main(String[] args){
Vector a = new Vector();
a.add (10);
System.out.println(a.get(0));
}
}
Select all right answers:
A:Prints 10
B:Prints 11
C:Compilations error
答案:A
第19题 (2.0分) 题号:1139 难度:中 第8章
Given:
class Hexy {
public static void main(String[] args) {
Integer i = 42;
String s = (i<40)?"life":(i>50)?"universe":"everything";
System.out.println(s);
}
}
What is the result?
A:null
B:life
C:universe
D:everything
E:Compilation fails.
F:An exception is thrown at runtime.
答案:D
第20题 (2.0分) 题号:1136 难度:中 第8章
what is the result when you compile and run the following code?
class Example
{
public static void main(String []args)
{
Short s=new Short("5");
Boolean b;
// insert code here
}
}
Which,inserted independently at //insert code here?,will compile?
Select all right answer:
A:b=(Number instanceof s);
B:b=(s instanceof Short);
C:b=s instanceof (Short);
D:b=(s instanceof Number);
E:b= s instanceof (Object);
F:b=(s instanceof String);
答案:BD