1、java考试选择题英文版Read the questions carefullyI have tried to make the questions unambiguous (the meaning should be obvious), but make sure you have read what I have written not what you think I might have written. Thus if it says Classes can be declared with the private modifier , it means It is possible
2、 to declare a class with the private modifier and not that all classes in all situations can be declared as private. Each question may have one or more correct Answers. QuestionsQuestion 1)Which of the following lines will compile without warning or error. 1) float f=1.3; 2) char c=a; 3) byte b=257;
3、 4) boolean b=null; 5) int i=10; Question 2)What will happen if you try to compile and run the following code public class MyClass public static void main(String arguments) amethod(arguments); public void amethod(String arguments) System.out.println(arguments); System.out.println(arguments1); 1) err
4、or Cant make static reference to void amethod. 2) error method main not correct 3) error array must include parameter 4) amethod must be declared with String Because main is defined as static you need to create an instance of the class in order to call any non-static methods.-Question 3)Which of the
5、 following will compile without error 要先出现package1) import java.awt.*;package Mypackage;class Myclass 2) package MyPackage;import java.awt.*;class MyClass3) /*This is a comment */package MyPackage;import java.awt.*;class MyClass-Question 4)A byte can be of what size 1) -128 to 127 2) (-2 power 8 )-1
6、 to 2 power 8 3) -255 to 256 4)depends on the particular implementation of the Java Virtual machine -Question 5)What will be printed out if this code is run with the following command line? Java myprog good morning;public class myprog public static void main(String argv) System.out.println(argv2); 1
7、) myprog 2) good 3) morning 4) Exception raised: java.lang.ArrayIndexOutOfBoundsException: 2 -Question 6)Which of the following are keywords or reserved (预定义)words in Java? 1) if 2) then 3) goto 4) while 5) case -Question 7)Which of the following are legal identifiers(标识符) 1) 2variable 2) variable2
8、3) _whatavariable 4) _3_ 5) $anothervar 6) #myvar -Question 8)What will happen when you compile and run the following code? public class MyClass static int i; public static void main(String argv) System.out.println(i); 局部变量(在函数内部)必须先初始化,类级别的可以不初始化Class level variables are always initialised to defau
9、lt values. In the case of an int this will be 0. Method level variables are not given default values and if you attempt to use one before it has been initialised it will cause the Error Variable i may not have been initialized1) Error Variable i may not have been initialized 2) null 3) 1 4) 0 -Quest
10、ion 9)What will happen if you try to compile and run the following code? public class Q public static void main(String argv) int anar=new int1,2,3; System.out.println(anar1); 1) 1 2) Error anar is referenced before it is initialized 3) 2 4) Error: size of array must be defined -Question 10)What will
11、 happen if you try to compile and run the following code? public class Q public static void main(String argv) int anar=new int5; System.out.println(anar0); 1) Error: anar is referenced before it is initialized 2) null 3) 0 4) 5 -Question 11)What will be the result of attempting to compile and run th
12、e following code? abstract class MineBase abstract void amethod(); static int i;public class Mine extends MineBase public static void main(String argv) int ar=new int5; for(i=0;i 2);will output a result larger than 10 无符号右移2) System.out.println( -1 2); will output a positive number 输出 -13) System.ou
13、t.println( 2 1); will output the number 1 4) System.out.println( 1 2); will output the number 4-Question 19)What will happen when you attempt to compile and run the following code?public class Tux extends Thread static String sName = vandeleur; public static void main(String argv) Tux t = new Tux();
14、 t.piggy(sName); System.out.println(sName); public void piggy(String sName) sName = sName + wiggy; start(); public void run() for(int i=0;i 4; i+) sName = sName + + i; 1) Compile time error2) Compilation and output of vandeleur wiggy3) Compilation and output of vandeleur wiggy 0 1 2 34) Compilation
15、and output of either vandeleur, vandeleur 0, vandeleur 0 1 vandaleur 0 1 2 or vandaleur 0 1 2 3-Question 20)What will be displayed when you attempt to compile and run the following code /Code startimport java.awt.*;public class Butt extends Frame public static void main(String argv) Butt MyBut=new B
16、utt(); Butt() Button HelloBut=new Button(Hello);Button ByeBut=new Button(Bye); add(HelloBut); add(ByeBut); setSize(300,300); setVisible(true); /Code end1) Two buttons side by side occupying all of the frame, Hello on the left and Bye on the right 2) One button occupying the entire frame saying Hello 3) One button occupying the entire frame saying Bye 4) Two buttons at the top of the frame one saying Hello the other saying Bye -Question 21)What will be output by the following code? public class MyFor public static void main(String argv) int i
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1