Question 1)
What will happen when you attempt to compile and run this code?
当试图编译并运行下面程序时会出现什么结果?
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[]){
base a = new Abs();
a. another ();
}
public void myfunc(){
System.out.println(“My Func”);
}
public void another (){
myfunc();
}
}
1) The code will compile and run, printing out the words “My Func”
代码编译、运行并打印出“My Func”
2) The compiler will complain that the base class has non abstract methods
编译器会报怨base class有非抽象方法
3) The code will compile but complain at run time that the base class has non abstract methods
代码可以编译通过,但运行时会报base class 有非抽象方法
4) The compiler will complain that the method myfunc in the base class has no body
编译器会报base class没有方法体
Answer to Question 1
——————————————————————————–
Question 2)
What will happen when you attempt to compile and run this code?
当试图编译并运行下面程序时会出现什么结果?
public class MyMain{
public static void main(String argv){
System.out.println(“Hello cruel world”);
}
}
1) The compiler will complain that main is a reserved word and cannot be used for a class
编译器报怨main属于保留字而不能在一个class中使用
2) The code will compile and when run will print out “Hello cruel world”
代码将编译、运行并输出“Hello cruel world”
3) The code will compile but will complain at run time that no constructor is defined
代码编译通过但运行时报没有定义构造方法
4) The code will compile but will complain at run time that main is not correctly defined
代码编译通过但运行时报main方法没有正确定义
Answer to Question 2
——————————————————————————–
Question 3)
Which of the following are Java modifiers?
下面哪些是java修饰符?
1) public
2) private
3) friendly
4) transient
5) vagrant
Answer to Question 3
——————————————————————————–
Question 4)
What will happen when you compile and run it.?
当编译并运行下面程序时会出现什么结果?
public class MyAr{
public static void main(String argv[]){
int[] i = new int[5];
System.out.println(i[5]);
}
}
1) An error at compile time
编译出错
2) An error at run time
运行出错
3) The value 0 will be output
输出0
4) The string “null” will be output
输出“null”
Answer to Question 4
——————————————————————————–
Question 5)
What best describes the appearance of an application with the following code?
下面哪个能最恰当的描述这个程序的运行效果?
import java.awt.*;
public class FlowAp extends frame{
public static void main(String argv[]){
FlowAp fa=new FlowAp();
fa.setSize(400,300);
fa.setVisible(true);
}
FlowAp(){
add(new Button(“One”));
add(new Button(“Two”));
add(new Button(“Three”));
add(new Button(“Four”));
}//End of constructor
}//End of Application
1)A frame with buttons marked One to Four placed on each edge.
窗体的每个边上依次放置按钮One到按钮Four
2) A frame with buttons marked One to four running from the top to bottom
按钮从上到下依次摆放在窗体上上
3) A frame with one large button marked Four in the Centre
按钮Four作为一个大的按钮放在窗体的中间
4) An Error at run time indicating you have not set a LayoutManager
运行出错,因为没有设置LayoutManager布局管理器
Answer to Question 5
——————————————————————————–
Question 6)
How do you change the current layout manager for a container
如何改变容器的布局管理器?
1) Use the setLayout method
采用setLayout方法
2) once created you cannot change the current layout manager of a container
一旦产生,你无法改变容器当前的布局管理器
3) Use the setLayoutManager method
采用setLayoutManager方法
4) Use the updateLayout method
采用updateLayout方法
Answer to Question 6)
——————————————————————————–
Question 7)
What most closely matches the appearance when this code runs?
当运行下面代码时,哪个最接近程序的结果?
import java.awt.*;
public class CompLay extends frame{
public static void main(String argv[]){
CompLay cl = new CompLay();
}
CompLay(){
Panel p = new Panel();
p.setBackground(Color.pink);
p.add(new Button(“One”));
p.add(new Button(“Two”));
p.add(new Button(“Three”));
add(“South”,p);
setLayout(new FlowLayout());
setSize(300,300);
setVisible(true);
}
}
1) The buttons will run from left to right along the bottom of the frame
按钮沿着窗体的底部从左到右摆放
2) The buttons will run from left to right along the top of the frame
按钮沿着窗体的顶部从左到右摆放
3) The buttons will not be displayed
所有按钮将不显示
4) only button three will show occupying all of the frame
只有按钮3显示并占据整个窗体
Answer to Question 7)
——————————————————————————–
Question 8)
What will happen when you attempt to compile and run the following code?
当编译并运行下面程序时会发生什么结果?
public class Bground extends Thread{
public static void main(String argv[]){
Bground b = new Bground();
b.run();
}
public void start(){
for (int i = 0; i <10; i++){System.out.println("Value of i = " + i);}}}1) A compile time error indicating that no run method is defined for the Thread class编译错误,指明run方法没有定义2) A run time error indicating that no run method is defined for the Thread class运行错误,指明run方法没有定义3) Clean compile and at run time the values 0 to 9 are printed out编译通过并输出0到94) Clean compile but no output at runtime编译通过但无输出Answer to Question 8)-------------------------------------------------------------------------------Question 9)For a class defined inside a method, what rule governs access to the variables of the enclosing method?对于定义在方法内部的类来说,它可以访问该方法的哪些变量?1) The class can access any variable可以访问任何变量2) The class can only access static variables只能访问静态变量3) The class can only access transient variables只能访问transient变量4) The class can only access final variables只能访问final常量Answer to Question 9)--------------------------------------------------------------------------------Question 10)What will happen when you attempt to compile and run the following code当编译并运行下面程序时会发生什么结果?public class Hope{public static void main(String argv[]){Hope h = new Hope();}protected Hope(){for(int i =0; i <10; i ++){System.out.println(i);}}}1) Compilation error: Constructors cannot be declared protected编译错误,构造方法不能被声明为protected2) Run time error: Constructors cannot be declared protected运行错误,构造方法不能被声明为protected3) Compilation and running with output 0 to 10编译并运行输出0到104) Compilation and running with output 0 to 9编译并运行输出0到9Answer to Question 10)--------------------------------------------------------------------------------Question 11)What will happen when you attempt to compile and run the following code当编译并运行下面程序时会发生什么结果?public class MySwitch{public static void main(String argv[]){MySwitch ms= new MySwitch();ms.amethod();}public void amethod(){int k=10; switch(k){ default: System.out.println("This is the default output"); break; case 10: System.out.println("ten");case 20: System.out.println("twenty"); break; }}}1) None of these options无解2) Compile time error target of switch must be an integral type编译错误,switch要求是integral类型3) Compile and run with output "This is the default output"编译并运行输出“This is the default output”4) Compile and run with output of the single line "ten"编译并运行输出“ten”Answer to Question 11)--------------------------------------------------------------------------------Question 12)Which of the following is the correct syntax for suggesting that the JVM performs garbage collectionJVM执行垃圾回收的正确语法是什么?1) System.free();2) System.setGarbageCollection();3) System.out.gc();4) System.gc();Answer to Question 12)--------------------------------------------------------------------------------Question 13)What will happen when you attempt to compile and run the following code当编译并运行下面程序时会发生什么结果?public class As{int i = 10;int j;char z= 1;boolean b;public static void main(String argv[]){As a = new As();a.amethod();}public void amethod(){System.out.println(j);System.out.println(b); }}1) Compilation succeeds and at run time an output of 0 and false编译并运行输出0和false2) Compilation succeeds and at run time an output of 0 and true编译并运行输出0和true3) Compile time error b is not initialized编译错误报变量b没有初始化4) Compile time error z must be assigned a char value编译错误,变量z必须赋予一个字符Answer to Question 13)--------------------------------------------------------------------------------Question 14)What will happen when you attempt to compile and run the following code当编译并运行下面程序时会发生什么结果?public class StrEq{public static void main(String argv[]){StrEq s = new StrEq();}private StrEq(){String s = "Marcus";String s2 = new String("Marcus");if(s == s2){System.out.println("we have a match");}else{System.out.println("Not equal");}}}1) Compile time error caused by private constructor编译错误报构造方法私有化2) Output of "we have a match"输出“we have a match”3) Output of "Not equal"输出“Not equal”4) Compile time error by attempting to compare strings using ==编译错误,由于采用了==作比较Answer to Question 14)--------------------------------------------------------------------------------Question 15)What will happen when you attempt to compile and run this program当编译并运行下面程序时会发生什么结果?public class Outer{public String name = "Outer";public static void main(String argv[]){Inner i = new Inner();i.showName();}//End of mainprivate class Inner{String name =new String("Inner");void showName(){System.out.println(name);}}//End of Inner class}1) Compile and run with output of "Outer"编译并运行输出“Outer”2) Compile and run with output of "Inner"编译并运行输出“Inner”3) Compile time error because Inner is declared as private编译错误,Inner被声明为private4) Compile time error because of the line creating the instance of Inner编译错误,由于产生Inner实例一行出错(Inner i = new Inner();)Answer to Question to 15--------------------------------------------------------------------------------Question 16)What will happen when you attempt to compile and run this code当编译并运行下面程序时会发生什么结果?//Demonstration of event handlingimport java.awt.event.*;import java.awt.*;public class MyWc extends frame implements WindowListener{public static void main(String argv[]){MyWc mwc = new MyWc();}public void windowClosing(WindowEvent we){System.exit(0);}//End of windowClosingpublic void MyWc(){setSize(300,300);setVisible(true);}}//End of class1) Error at compile time编译出错2) Visible frame created that that can be closed窗体可见并且可以关闭3) Compilation but no output at run time编译通过但无输出4) Error at compile time because of comment before import statements由于import前面有注释导致编译出错Answer to Question 16)--------------------------------------------------------------------------------Question 17)Which option most fully describes will happen when you attempt to compile and run the following code当编译和运行下面程序时,哪项描述可以最准确的表达发生了什么事情?public class MyAr{public static void main(String argv[]) {MyAr m = new MyAr();m.amethod();}public void amethod(){static int i;System.out.println(i);}}1) Compilation and output of the value 0编译并输出02) Compile time error because i has not been initialized编译错误,因为i没有初始化3) Compilation and output of null编译并输出null4) Compile time error编译错误Answer to Question 17)--------------------------------------------------------------------------------Question 18)Which of the following will compile correctly下面哪一个编译正确?1) short myshort = 99S;2) String name = 'Excellent tutorial Mr Green';3) char c = 17c;4)int z = 015;Answer to Question 18)--------------------------------------------------------------------------------Question 19)Which of the following are Java key words哪些是java关键字?1)double2)Switch3)then4)instanceofAnswer to Question 19)--------------------------------------------------------------------------------Question 20)What will be output by the following line?下面程序的输出是什么?System.out.println(Math.floor(-2.1));1) -22) 2.03) -34) -3.0Answer to Question 20)--------------------------------------------------------------------------------Question 21)Given the following main method in a class called Cycle and a command line of看下面的Cycle程序,执行下面的命令java Cycle one twowhat will be output?结果是什么?public static void main(String bicycle[]){System.out.println(bicycle[0]);}1) None of these options2) cycle3) one4) twoAnswer to Question 21)--------------------------------------------------------------------------------Question 22)Which of the following will compile without error 下面哪些编译正确?1) import java.awt.*;package Mypackage;class Myclass {}2) package MyPackage;import java.awt.*;class MyClass{}3) package MyPackage;import java.awt.*;class MyClass{}Answer to Question 3 --------------------------------------------------------------------------------Question 23)Which of the following statements are true?下面哪个叙述是正确的?1) At the root of the collection hierarchy is a class called CollectionCollection类是集合类的根2) The collection interface contains a method called enumeratorCollection接口包含一个方法enumerator3) The iterator method returns an instance of the Vector classIterator方法返回Vector类的一个实例4) The set interface is designed for unique elementsset接口用于存放不同元素的Answer to Question 23)--------------------------------------------------------------------------------Question 24)Given the following code考虑下面的代码class base{}public class MyCast extends base{static boolean b1=false;static int i = -1;static double d = 10.1;public static void main(String argv[]){MyCast m = new MyCast();base b = new base();//Here}}Which of the following, if inserted at the comment //Here will allow the code to compile and run without error下面哪些代码,当被插入//here所指地方时,编译和运行不会出错1) b=m;2) m=b;3) d =i;4) b1 =i;Answer to Question 24)--------------------------------------------------------------------------------Question 25)Which of the following statements about threading are true下面关于线程的叙述哪些是正确的?1) You can only obtain a mutually exclusive lock on methods in a class that extends Thread or implements runnable你只能在继承Thread或者实现runnable接口的类的方法上获取互斥锁2) You can obtain a mutually exclusive lock on any object你可以在任何对象上获得互斥锁3) A thread can obtain a mutually exclusive lock on a synchronized method of an object 一个线程可以获得一个synchronized同步方法上的互斥锁4) Thread scheduling algorithms are platform dependent线程调度算法跟平台有关Answer to Question 25)--------------------------------------------------------------------------------Question 26)What will happen when you attempt to compile and run the following code当编译和运行下面代码时会发生什么?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);}1) Compile error, attempting to peform binary comparison on logical data type编译错误,因为在逻辑数据类型上作比较2) Compilation and output of "We are equal 10"编译并输出"We are equal 10"3) Compilation and output of "Not equal! 20"编译并输出"Not equal! 20"4) Compilation and output of "Not equal! 10"编译并输出"Not equal! 10"Answer to Question 26)--------------------------------------------------------------------------------Question 27)What will be output by the following line of code?这行代码输出是什么?System.out.println(010|4);1) 142) 03) 64) 12Answer to Question 27)--------------------------------------------------------------------------------Question 28)Which of the following will compile without error?下面哪句代码编译没有错误?1) File f = new File("/","autoexec.bat");2) DataInputStream d = new DataInputStream(System.in);3) OutputStreamWriter o = new OutputStreamWriter(System.out);4) RandomAccessFile r = new RandomAccessFile("OutFile");Answer to Question 28)--------------------------------------------------------------------------------Question 29)Given the folowing classes which of the following will compile without error?下面哪个编译没有错误?interface IFace{}class CFace implements IFace{}class base{}public class ObRef extends base{public static void main(String argv[]){ObRef ob = new ObRef();base b = new base();Object o1 = new Object();IFace o2 = new CFace();}}1)o1=o2;2)b=ob;3)ob=b;4)o1=b;Answer to Question 29)--------------------------------------------------------------------------------Question 30)Given the following code what will be the output?下面代码的输出结果是什么?class ValHold{public int i = 10;}public class ObParm{public static void main(String argv[]){ObParm o = new ObParm();o.amethod();}public void amethod(){int i = 99;ValHold v = new ValHold();v.i=30;another(v,i);System.out.println(v.i);}//End of amethodpublic void another(ValHold v, int i){i=0;v.i = 20;ValHold vh = new ValHold();v = vh;System.out.println(v.i+ " "+i);}//End of another}1) 10,0, 302) 20,0,303) 20,99,304) 10,0,20Answer to Question 30)--------------------------------------------------------------------------------Question 31)Given the following class definition, which of the following methods could be legally placed after the comment//Here 下面哪个方法可以放在注释//here处?public class Rid{public void amethod(int i, String s){}//Here}1)public void amethod(String s, int i){}2)public int amethod(int i, String s){}3)public void amethod(int i, String mystring){} 4) public void Amethod(int i, String s) {}Answer to Question 31)--------------------------------------------------------------------------------Question 32)Given the following class definition which of the following can be legally placed after the comment line//Here ?下面哪个方法可以放在注释//here处?class base{public base(int i){}}public class MyOver extends base{public static void main(String arg[]){MyOver m = new MyOver(10);}MyOver(int i){super(i);}MyOver(String s, int i){this(i);//Here}}1)MyOver m = new MyOver();2)super(); 3)this("Hello",10);4)base b = new base(10);Answer to Question 32)--------------------------------------------------------------------------------Question 33)Given the following class definition, which of the following statements would be legal after the comment //Here下面哪个方法可以放在注释//here处?class InOut{String s= new String("Between");public void amethod(final int iArgs){int iam;class Bicycle{public void sayHello(){//Here}//End of bicycle class}}//End of amethodpublic void another(){int iOther;}}1)System.out.println(s); 2) System.out.println(iOther);3) System.out.println(iam);4) System.out.println(iArgs);Answer to Question 33)--------------------------------------------------------------------------------Question 34)Which of the following are methods of the Thread class?哪些是Thread类中的方法?1) yield()2) sleep(long msec)3) go()4) stop(),wait(),wait(100),notify(),notifyAll()Answer to Question 34)--------------------------------------------------------------------------------Question 35)Which of the following methods are members of the Vector class and allow you to input a new element下面哪些是Vector类中的方法并且可以插入新的元素进去?1) addElement2) insert3) append4) addItemAnswer to Question 35)--------------------------------------------------------------------------------Question 36)Which of the following statements are true?下面哪些为真?1) Adding more classes via import statements will cause a performance overhead, only import classes you actually use.添加很多的import语句会导致性能问题,只需倒入实际需要的就行2) Under no circumstances can a class be defined with the private modifier任何情况下,类都不能被private修饰3) A inner class may under some circumstances be defined with the protected modifier内部类在某些情况下可以被protected修饰4) An interface cannot be instantiated接口不能实例化Answer 36)--------------------------------------------------------------------------------Question 37)Which of the following are correct event handling methods下面哪些是正确的事件处理方法?1) mousePressed(MouseEvent e){}2) MousePressed(MouseClick e){}3) functionKey(KeyPress k){}4) componentAdded(ContainerEvent e){}Answer 37)--------------------------------------------------------------------------------Question 38)Which of the following are methods of the Collection interface?下面哪些是接口Collection中的方法?1) iterator2) isEmpty3) toArray4) setTextAnswer 38)--------------------------------------------------------------------------------Question 39)Which of the following best describes the use of the synhronized keyword?下面哪些是正确的描述了关键字synhronized1) Allows two process to run in paralell but to communicate with each other允许两个进程并行运行但其之间相互通信2) Ensures only one thread at a time may access a method or object保证任何时候只有一个线程访问一个方法或对象3) Ensures that two or more processes will start and end at the same time保证两个或多个进程同时启动和结束4) Ensures that two or more Threads will start and end at the same time保证两个或多个线程同时启动和结束Answer 39)--------------------------------------------------------------------------------Question 40)Which of the following lines will compile without warning or error. 下面哪些编译时没有警告或错误?1) float f=1.3; 2) char c="a"; 3) byte b=257; 4) boolean b=null; 5) int i=10;Answer 40)--------------------------------------------------------------------------------



