尔雅Java语言程序设计E答案(学习通2023课后作业答案)

尔雅Java语言程序设计E答案(学习通2023课后作业答案)

复习测试

复习测试

1、尔雅What is 程序best to describe the relationship between Component and Font?
A、Association
B、设计Aggregation
C、答答案Composition
D、案学Inheritance
E、习通244

2、课后下面三个表达式中,作业正确的尔雅是 ___________. 1. frame.setLocationRelativeTo(null); 2. frame.setSize(100, 200); 3. frame.setVisible(true);
A、1 2 3
B、程序1 3 2
C、设计2 1 3
D、答答案3 2 1
E、案学245

3、习通How many frames are displayed?课后 import javax.swing.*; public class Test extends JFrame { public static void main(String[] args) { JFrame f1 = new Test(); JFrame f2 = new Test(); JFrame f3 = new Test(); f1.setVisible(true); f2.setVisible(true); f3.setVisible(true); } }
A、1
B、2
C、3
D、0
E、246

4、Jpanel的缺省布局方式是__________________.
A、FlowLayout
B、GridLayout
C、BorderLayout
D、None
E、247

5、方法________________将给Jpanel p增加一个组件 c。
A、p.add(c)
B、p.getContentPane(c)
C、p.insert(c)
D、p.append(c)
E、248

6、Analyze the following code: import javax.swing.*; public class Test extends JFrame { private JButton jbtOK = new JButton("OK"); public static void main(String[] args) { // Create a frame and set its properties JFrame frame = new Test(); frame.setTitle("Logic Error"); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } public Test() { jbtOK.setToolTipText("This is a button"); add(new JButton("OK")); } }
A、The tool tip text is displayed when you move the mouse on the button.
B、The tool tip text will be displayed if you replace add(new JButton("OK")) with add(jbtOK).
C、The tool tip text will be displayed if you swap the two lines in the Test constructor.
D、The tool tip text will be displayed if you replace add(new JButton("OK")) with add(jbtOK = new JButton("OK")).
E、249

7、Show the output of the following code? import javax.swing.*; public class Test { public static void main(String[] args) { JButton jbtOK = new JButton("OK"); System.out.print(jbtOK.isVisible() + ", "); JFrame frame = new JFrame(); System.out.println(frame.isVisible()); } }
A、true, true
B、true, false
C、false, true
D、false, false
E、250

8、方法_________设置按钮jbt上的文字放在图标的右边。
A、jbt.setVerticalTextPosition(JButton.LEFT)
B、jbt.setHorizontalTextPosition(JButton.LEFT)
C、jbt.setHorizontalTextPosition(JButton.RIGHT)
D、jbt.setHorizontalAlignment(JButton.RIGHT)
E、251

9、The method __________ specifies that the text and icon are horizontally aligned to the right in the button jbt.
A、jbt.setVerticalTextPosition(JButton.LEFT)
B、jbt.setHorizontalTextPosition(JButton.LEFT)
C、jbt.setHorizontalTextPosition(JButton.RIGHT)
D、jbt.setHorizontalAlignment(JButton.RIGHT)
E、252

10、Analyze the following code: import javax.swing.*; import javax.swing.border.*; import java.awt.*; public class Test extends JFrame { public Test() { Border border = new TitledBorder("My button"); JButton jbt1 = new JButton("OK"); JButton jbt2 = new JButton("Cancel"); jbt1.setBorder(border); jbt2.setBorder(border); add(jbt1, BorderLayout.NORTH); add(jbt2, BorderLayout.SOUTH); } public static void main(String[] args) { JFrame frame = new Test(); frame.setSize(200, 100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
A、Two buttons displayed with the same border.
B、Two buttons displayed, but only one button has the border.
C、The program has a compile error because you assign new TitledBorder("My button") to a variable of the Border type.
D、The program has a runtime error because you cannot set a border on a button.
E、253

11、方法___________将获取标签jlbl上的文本。
A、jlbl.text()
B、jlbl.getText()
C、jlbl.findText()
D、jlbl.retrieveText().
E、254

12、The method __________ specifies that the text is placed on the right of the icon in the label jlbl.
A、jlbl.setVerticalTextPosition(JButton.LEFT)
B、jlbl.setHorizontalTextPosition(JButton.LEFT)
C、jlbl.setHorizontalTextPosition(JButton.RIGHT)
D、jlbl.setHorizontalAlignment(JButton.RIGHT)
E、255

13、___________能够输入或者显示一个字符串。
A、A label
B、A button
C、A check box
D、radio button
E、256

14、一个字节包含 ________ 位
A、4
B、8
C、12
D、16
E、1

15、方法__________用来获取文本控件jtf上的内容。
A、jtf.getText(s)
B、jtf.getText()
C、jtf.getString()
D、jtf.findString()
E、257

16、Which of the following statements is correct?
A、Every line in a program must end with a semicolon
B、Every statement in a program must end with a semicolon
C、Every comment line must end with a semicolon
D、Every method must end with a semicolon
E、2

17、The method __________ appends a string s into the text area jta.
A、jta.setText(s)
B、jta.appendText(s)
C、jta.append(s)
D、jta.insertText(s)
E、258

18、java字节码文件的后缀是
A、.java
B、.obj
C、.class
D、.exe
E、3

19、To wrap a line in a text area jta, invoke ____________.
A、jta.setLineWrap(false)
B、jta.setLineWrap(true)
C、jta.WrapLine()
D、jta.wrapText()
E、259

20、Java ___________ can run from a Web browser
A、applications
B、applets
C、servlets
D、Micro Edition programs
E、4

线程测验

1、编写线程类,要继承的父类是 ( )
A、Thread
B、Runnable
C、Serializable
D、Exception

2、以下哪个最准确地描述了 synchronized 关键字?
A、保证在某时刻只有一个线程可访问方法或对象
B、保证两个或更多线程同时开始和结束
C、保证允许两个或更多处理同时开始和结束
D、允许两线程并行运行,而且互相通信

3、下列说法中错误的一项是( )
A、线程操作的数据来自Runnable实例
B、新建的线程调用start()方法就能立即进入运行状态
C、线程从传递给它的Runnable实例的run()方法开始执行
D、一个线程是一个Thread类的实例

4、在Java多线程中,请用下面哪种方式不会使线程进入阻塞状态?
A、sleep()
B、suspend()
C、wait()
D、yield()

5、关于ArrayList 和 Vector 的区别,以下说法正确的是 ( )
A、ArrayList是线程安全的,Vector是线程不安全的
B、ArrayList底层是链表结构,Vector底层是数组结构
C、ArrayList底层是数组结构,Vector底层是链表结构
D、ArrayList是线程不安全的,Vector是线程安全的

6、有以下代码: public class TestMultiThread { public static void main(String[] args) { Thread t = new Thread() { public void run(){ pong(); } }; t.run(); System.out.println("ping"); } static void pong(){ System.out.println("pong"); } } 请问程序的运行结果是( )?
A、pong ping
B、ping ping
C、ping 和 pong 的输出顺序不确定,取决于线程的执行顺序
D、都不输出

7、若要启动一个线程,必须调用 ( ) 方法。
A、new
B、run
C、start
D、resume

8、下列哪一种情况不会终止当前线程的运行?
A、当创建一个新线程时
B、当该线程调用 sleep 方法时
C、抛出一个异常时
D、当一个优先级更高的线程进入就绪状态时

9、下面所述步骤中,创建进程做必须的步骤包括( )
A、为进程分配内存
B、为进程分配文件描述符
C、建立一个进程控制块
D、由调度程序为进程分配 CPU

10、以下( ) 方法可以用来暂时停止当前线程的运行。
A、stop()
B、sleep()
C、wait()
D、suspend()

异常测验

1、给出如下代码段: try?{ ?int?x?=?Integer.parseInt("two");?} 下列哪个可以作为catch的异常?
A、ClassCastException
B、IllegalStateException
C、NumberFormatException
D、ExceptionInInitializerError

2、给出下列代码: class?Plane?{ static?String?s?=?"-"; public?static?void?main(String[]?args){ new?Plane().s1(); System.out.println(s); } void?s1()?{ try?{ s2();}catch?(Exception?e){ ?s?+=?"c";? } } void?s2()?throws?Exception?{ s3();? s?+=?"2"; s3(); s?+=?"2b"; } void?s3()?throws?Exception{ throw?new?Exception(); } } 结果是什么?
A、-
B、-c
C、-c2
D、-2c

3、下列程序的执行,说法正确的是( ) class MultiCatch { public static void main(String args[]) { try { int a=args.length; int b=42/a; int c[]={ 1}; c[42]=99; //10行 System.out.println(“b=”+b); } catch(ArithmeticException e) { System.out.println(“除0异常:”+e); //15行 } catch(ArrayIndexOutOfBoundsException e) { System.out.println(“数组超越边界异常:”+e); //19行 } } }
A、程序将输出第15行的异常信息
B、程序第10行出错
C、程序将输出“b=42”
D、程序将输出第19行的异常信息

4、下面是一些异常类的层次关系: java.lang.Exception java.lang.RuntimeException java.lang.IndexOutOfBoundsException java.lang.ArrayIndexOutOfBoundsException java.lang.StringIndexOutOfBoundsException 假设有一个方法X,能够抛出两个异常,Array Index和String Index异常,假定方法X中没有try-catch语句处理这些异常,下面哪个答案是正确的?( )
A、方法X 应该声明抛弃ArrayIndexOutOfBoundsException和StringIndexOutOfBounds-Exception。
B、如果调用X的方法捕获IndexOutOfBoundsException,则ArrayIndexOutOfBoundsException和StringIndexOutOfBoundsException都可以被捕获。
C、如果方法X声明抛弃IndexOutOfBoundsException,则调用X的方法必须用try-catch语句捕获。
D、方法X不能声明抛弃异常。

5、请问所有的异常(Exception)和错误(Error)类皆继承哪一个类?( )
A、java.lang.Throwable
B、java.lang.Exception
C、java.lang.Error
D、java.io.Exception

6、pubic void test () { try { oneMethod (); System.out.print ( "condition 1"); } catch ( Exception e ) { System.out.print ( "condition 3"); } catch ( ArithmeticException e ) { System.out.print ( "condition 2" ); } finally { System.out.println ("condition 4" ); } } Which will display if oneMethod throw NullPointerException?
A、condition 1 Condition4
B、condition 2 Condition4
C、condition 3 Condition4
D、error in compilation

7、Given: import?java.io.*; class?Master?{ String?doFileStuff()?throws?FileNotFoundException?{ ? return?"a"; ?} } class?Slave?extends?Master?{ public?static?void?main(String[]?args){ String?s?=?null; try?{ ? s?=?new?Slave().doFileStuff();}catch?(?Exception?x){ s?=?"b";? } System.out.println(s); } //?insert?code?here } Which,?inserted?independently?at?//?insert?code?here,?will?compile,?and?produce?the?output b??(Choose?all?that?apply.)
A、String doFileStuff() { return "b"; }
B、String doFileStuff() throws IOException { return "b"; }
C、String doFileStuff(int x) throws IOException { return "b"; }
D、String doFileStuff() throws Exception { return "b"; }

8、Given import java.io.*; class Main{ public void f1() throws ArithmeticException{ } public void f2() throws FileNotFoundException{ } public static void main(){ new Main().f1(); //line1 new Main().f2(); //line2 } } Which is correct?
A、No error in compilation
B、error at //line1 in compilation
C、error at //line2 in compilation
D、two errors at //line1 and //line2 in compilation

9、class Emu{ static String s = "-"; public static void main(String[] args){ try{ throw new Exception(); }catch(Exception e){ try{ try{ throw new Exception(); }catch (Exception ex){ s += "ic "; } throw new Exception(); } catch(Exception x){ s += "mc "; } finally{ s += "mf "; } }finally{ s += "of "; } System.out.println(s); } } What is the result?
A、-ic mf of
B、-ic mc mf of
C、-ic mc of mf
D、Compilation fails

10、Given: class Mineral{ } class Gem extends Mineral{ } class Miner{ static int x = 7; static String s = null; public static void getWeight(Mineral m){ int y = 0 / x; System.out.print(s + " "); } public static void main(String[] args){ Mineral[] ma = { new Mineral(), new Gem()}; for(Object o : ma) getWeight((Mineral) o); } } And the command-line invocation: java Miner What is the result?
A、null
B、null null
C、A ClassCastException is thrown.
D、A NullPointerException is thrown.

复习测验1

1、The signature of a method consists of ________
A、method name
B、method name and parameter list
C、return type, method name, and parameter list
D、parameter list

2、Suppose your method does not return any value, which of the following keywords can be used as a return type?
A、void
B、int
C、double
D、None of the above

3、Suppose you wish to provide an accessor method for a boolean property finished, what signature of the method should be?
A、public void getFinished()
B、public boolean getFinished()
C、public boolean isFinished()
D、public void isFinished()

4、Suppose the xMethod() is invoked from a main method in a class as follows, xMethod() is _________ in the class. public static void main(String[] args) { xMethod(); }
A、a static method
B、an instance method
C、a static method or an instance method
D、an Object method

5、Given: 3. public class Dark { 4. int x = 3; 5. public static void main(String[] args) { 6. new Dark().go1(); 7. } 8. void go1() { 9. int x; 10. go2(++x); 11. } 12. void go2(int y) { 13. int x = ++y; 14. System.out.println(x); 15. } 16. } What is the result?
A、3
B、4
C、5
D、Compilation fails

6、Given: 1. public class Yippee { 2. public static void main(String [] args) { 3. for(int x = 1; x < args.length; x++) { 4. System.out.print(args[x] + " "); 5. } 6. } 7. } and two separate command line invocations: java Yippee java Yippee 1 2 3 4 What is the result?
A、No output is produced. 1 2 3
B、No output is produced. 2 3 4
C、No output is produced. 1 2 3 4
D、An exception is thrown at runtime. 1 2 3

7、Given: 1. public class Pass { 2. public static void main(String [] args) { 3. int x = 5; 4. Pass p = new Pass(); 5. p.doStuff(x); 6. System.out.print(" main x = " + x); 7. } 8. 9. void doStuff(int x) { 10. System.out.print(" doStuff x = " + x++); 11. } 12. } What is the result?
A、doStuff x = 6 main x = 6
B、doStuff x = 5 main x = 5
C、doStuff x = 5 main x = 6
D、doStuff x = 6 main x = 5

8、Given: 1. public class Frodo extends Hobbit { 2. public static void main(String[] args) { 3. Short myGold = 7; 4. System.out.println(countGold(myGold, 6)); 5. } 6. } 7. class Hobbit { 8. int countGold(int x, int y) { return x + y; } 9. } What is the result?
A、13
B、Compilation fails due to multiple errors
C、Compilation fails due to an error on line 1
D、Compilation fails due to an error on line 4

9、Given: 1. public class Batman { 2. int squares = 81; 3. public static void main(String[] args) { 4. new Batman().go(); 5. } 6. void go() { 7. incr(++squares); 8. System.out.println(squares); 9. } 10. void incr(int squares) { squares += 10; } 11. } What is the result?
A、81
B、82
C、91
D、92

10、Given: 1. class Voop { 2. public static void main(String[] args) { 3. doStuff(1); 4. doStuff(1,2); 5. } 6. // insert code here 7. } Which, inserted independently at line 6, will compile?
A、static void doStuff(int... doArgs) { }
B、static void doStuff(int[] doArgs) { }
C、static void doStuff(int doArgs...) { }
D、static void doStuff(int... doArgs, int y) { }

11、Given: 1. class Voop { 2. public static void main(String[] args) { 3. doStuff(1); 4. doStuff(1,2); 5. } 6. // insert code here 7. } Self Test Answers 79 80 Chapter 1: Declarations and Access Control Which, inserted independently at line 6, will compile?
A、static void doStuff(int... doArgs) { }
B、static void doStuff(int[] doArgs) { }
C、static void doStuff(int doArgs...) { }
D、static void doStuff(int... doArgs, int y) { }

12、Given the following code what will be output? public class Pass{ static int j=20; public static void main(String argv[]){ int i=10; Pass p = new Pass(); p.amethod(i); System.out.println(i); System.out.println(j); } public void amethod(int x) { x=x*2; j=j*2; } }
A、Error: amethod parameter does not match variable
B、20 and 40
C、10 and 40
D、10 and 20

13、Analyze the following code: class Test { public static void main(String[] args) { System.out.println(xMethod((double)5)); } public static int xMethod(int n) { System.out.println("int"); return n; } public static long xMethod(long n) { System.out.println("long"); return n; } }
A、The program displays int followed by 5
B、The program displays long followed by 5
C、The program runs fine but displays things other than given in a and b
D、The program does not compile

14、Analyze the following code: public class Test { public static void main(String[] args) { System.out.println(xMethod(5, 500L)); } public static int xMethod(int n, long l) { System.out.println("int, long"); return n; } public static long xMethod(long n, long l) { System.out.println("long, long"); return n; } }
A、The program displays int, long followed by 5
B、The program displays long, long followed by 5
C、The program runs fine but displays things other than 5
D、The program does not compile because the compiler cannot distinguish which xmethod to invoke

15、Analyze the following code. public class Test { public static void main(String[] args) { int n = 2; xMethod(n); System.out.println("n is " + n); } void xMethod(int n) { n++; } }
A、The code has a compile error because xMethod does not return a value
B、The code has a compile error because xMethod is not declared static
C、The code prints n is 2
D、The code prints n is 3

16、All Java applications must have a method ______
A、public static Main(String[] args)
B、public static Main(String args[])
C、public static void main(String[] args)
D、None of the above

17、A variable defined inside a method is referred to as _____
A、a global variable
B、a method variable
C、a block variable
D、a local variable

18、A method that is associated with an individual object is called ____
A、a static method
B、a class method
C、an instance method
D、an object method

19、有以下方法的定义,请选择该方法的返回类型 ReturnType method(byte x, double y) { return (short)x/y*2; }
A、byte
B、short
C、int
D、double

20、Which of the following statements are correct?
A、char[][] charArray = { 'a', 'b'};
B、char[2][2] charArray = { { 'a', 'b'}, { 'c', 'd'}};
C、char[2][] charArray = { { 'a', 'b'}, { 'c', 'd'}};
D、char[][] charArray = { { 'a', 'b'}, { 'c', 'd'}};

21、Suppose a method p has the following heading: public static int[] p() What return statement may be used in p()?
A、return 1;
B、return { 1, 2, 3};
C、return int[]{ 1, 2, 3};
D、return new int[]{ 1, 2, 3};

22、If you declare an array double[] list = { 3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________
A、0
B、3
C、4
D、5

23、for-each loop) Analyze the following code: public class Test { public static void main(String[] args) { double[] x = { 2.5, 3, 4}; for (double value: x) System.out.print(value + " "); } }
A、The program displays 2.5, 3, 4
B、The program displays 2.5 3 4
C、The program displays 2.5 3.0 4.0
D、The program displays 2.5, 3.0 4.0

24、Analyze the following code: public class Test { public static void main(String[] args) { int[] x = { 1, 2, 3, 4}; int[] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } }
A、The program displays 1 2 3 4
B、The program displays 0 0
C、The program displays 0 0 3 4
D、The program displays 0 0 0 0

25、执行完以下代码int [ ] x = new int[25];后,以下哪项说明是正确的( )
A、x[24]为0
B、x[24]未定义
C、x[25]为0
D、x[0]为空

26、有关类Demo,哪句描述是正确的? ( ) public class Demo extends Base{ private int count; public Demo(){ System.out.println("A Demo object has been created"); } protected void addOne() { count++;} }
A、当创建一个Demo类的实例对象时,count的值为0
B、当创建一个Demo类的实例对象时,count的值是不确定的.
C、超类对象中可以包含改变count 值的方法。
D、Demo的子类对象可以访问count。

27、以下说法错误的是【 】
A、Applet小应用程序不可以独立运行
B、一个JAVA源程序可以没有public修饰的类
C、在一个JAVA源程序中可以定义多个类
D、一个java源程序可以有多个public修饰的类

28、以下说法不正确的是【 】
A、private修饰的成员变量可以在本类或其本包中子类中使用
B、java类可以同时实现多个接口,但只能继承一个父类
C、static修饰的成员变量可以不经过实例化直接通过类名引用
D、static不可以和abstract修饰符同时使用

29、以下哪个类能正确编译?【 】
A、class a{ abstract void disp(); }
B、abstract class a{ void disp(){ System.out.println("welcome to Beijing!"); } }
C、class a{ abstract void disp(){ System.out.println("welcome to Beijing!"); } }
D、abstract class a{ final abstract void disp(); }

30、已知在一个类中能正确使用命令:import hr.tech.Wage。以下说法不正确的是【 】
A、Wage是类名
B、在Wage类中声明包的命令是package hr.tech
C、hr.tech.Wage是包名
D、不使用import hr.tech.Wage语句,也可使用new hr.tech.Wage()的方式产生对象

复习测验2

1、要想定义一个不能被实例化的抽象类,在类定义中必须加上修饰符( )。
A、final
B、public
C、private
D、abstract

2、下述说法中,错误的是
A、Java中,方法的重载是指多个方法可以共享同一个名字
B、Java中,用abstract修饰的类称为抽象类,它不能实例化
C、Java中,接口不包含方法实现
D、Java中,构造方法可以有返回值

3、下面哪个函数不是public void example(){ ...}的重载函数【 】
A、public void example( int m){ ...}
B、public int example(){ ...}
C、public void example(float f){ ...}
D、public int example ( int m, float f){ ...}

4、下列哪一种叙述是正确的( )
A、abstract修饰符可修饰字段、方法和类
B、抽象方法的body部分必须用一对大括号{ }包住
C、声明抽象方法,大括号可有可无
D、声明抽象方法不可写出大括号

5、下列关于修饰符混用的说法,错误的是( )
A、abstract不能与final并列修饰同一个类
B、abstract类中不可以有private的成员
C、abstract方法必须在abstract类中
D、static方法中能处理非static的属性

6、为AB类的一个无形式参数无返回值的方法method书写方法头,使得使用类名AB作为前缀就可以调用它,该方法头的形式为( )。
A、static void method( )
B、public void method( )
C、final void method( )
D、abstract void method( )

7、如果类中的成员变量可以被同一包访问,则使用如下哪个约束符【 】
A、private
B、public
C、protected
D、缺省约束符

8、类Test1定义如下: 1.public class Test1{ 2. public float aMethod(float a,float b){ } 3. 4.} 将以下哪种方法插入行3是不合法的。( )
A、public float aMethod(float a, float b,float c){ }
B、public float aMethod(float c,float d){ }
C、public int aMethod(int a, int b){ }
D、private float aMethod(int a,int b,int c){ }

9、设已声明了一个类A的两个对象a1,a2,为了初始化 a1和a2,下面语句正确的是
A、a1,a2=new A();
B、a1=A.new(); a2=A.new();
C、a1=new();a2=new();
D、a1=new A();a2=new A();

10、关于以下说法,描述错误的是【 】
A、在JAVA应用程序中main方法里,不能直接使用非静态变量
B、有abstract修饰的类能够直接实例化
C、一个非抽象类实现一个接口,在该类中必须重写该接口中所有的方法
D、this和super这两个特殊变量只能用在非静态方法中

11、若JAVA程序中定义了3个类,编译后可生成(   )个字节码文件。
A、4
B、3
C、2
D、1

12、关于以下程序代码的说明正确的是( ) 1. class HasStatic{ 2. private static int x=100; 3. public static void main(String args[ ]){ 4. HasStatic hs1=new HasStatic( ); 5. hs1.x++; 6. HasStatic hs2=new HasStatic( ); 7. hs2.x++; 8. hs1=new HasStatic( ); 9. hs1.x++; 10. HasStatic.x- -; 11. System.out.println("x="+x); 12. } 13. }
A、5行不能通过编译,因为引用了私有静态变量
B、10行不能通过编译,因为x是私有静态变量
C、程序通过编译,输出结果为:x=103
D、程序通过编译,输出结果为:x=102

13、哪个关键字修饰的变量和方法不能从其他类访问?
A、protected
B、public
C、private
D、default

14、关于被私有访问控制符private修饰的成员变量,以下说法正确的是
A、可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类
B、可以被两种类访问和引用:该类本身、该类的所有子类
C、只能被该类自身所访问和修改
D、只能被同一个包中的类访问

15、哪个关键字声明一个常量?
A、protected
B、static
C、final
D、default

16、关于被保护访问控制符protected修饰的成员变量,以下说法正确的是
A、可以被三种类所引用:该类自身、与它在同一个包中的其他类、在其他包中的该类的子类
B、可以被两种类访问和引用:该类本身、该类的所有子类
C、只能被该类自身所访问和修改
D、只能被同一个包中的类访问

17、哪个表达式的结果为0.5?
A、1 / 2
B、(double) (1 / 2)
C、(double) 1 / 2
D、1 \ 2

18、给定以下代码 3. public class TestDays { 4. public enum Days { MON, TUE, WED }; 5. public static void main(String[] args) { 6. for(Days d : Days.values() ) 7. ; 8. Days [] d2 = Days.values(); 9. System.out.println(d2[2]); 10. } 11. } 结果正确的是?
A、TUE
B、WED
C、输出不可预料
D、编译错

19、不是构造函数特点的是( )
A、构造函数与类名相同
B、构造函数可带参数也可不带
C、构造函数带有返回类型
D、构造函数主要完成对类对象的初始工作

20、给出下面的代码段 public class Base{ int w, x, y ,z; public Base(int a,int b) { x=a; y=b; } public Base(int a, int b, int c, int d){ ________________ w=d; z=c; } } 在代码说明________处写入如下哪一个代码是正确的?【 】
A、a=x; b=y;
B、x=a, y=b;
C、super(a,b)
D、this(a,b)

21、编译Java Application 源程序文件将产生相应的字节码文件,这些字节码文件的扩展名为( )。
A、.java
B、.class
C、.obj
D、.jdk

22、不允许作为类及类成员的访问控制符的是( )。
A、public
B、private
C、static
D、protected

23、You have a public class called myclass with the main method defined as follows public static void main(String parm[]){ System.out.println(parm[0]); } If you attempt to compile the class and run the program as follows java myclass hello What will happen?
A、Compile time error, main is not correctly defined
B、Run time error, main is not correctly defined
C、Compilation and output of java
D、Compilation and output of hello

24、Which of the following are correct statements to create a Lock so the longest-wait thread will obtain the lock first?()
A、Lock lock = new Lock();
B、Lock lock = new ReentrantLock();
C、Lock lock = new ReentrantLock(true);
D、Lock lock = new ReentrantLock(false);

25、Which specifier essentially declares a variable a global variable?
A、protected
B、static
C、final
D、default

26、如何在Condition对象实例上创建线程锁?()
A、Condition condition = lock.getCondition();
B、Condition condition = lock.newCondition();
C、Condition condition = Lock.newCondition();
D、Condition condition = Lock.getCondition();

27、Which of the following statement prints smith\exam1\test.txt?
A、System.out.println("smith\exam1\test.txt");
B、System.out.println("smith\\exam1\\test.txt");
C、System.out.println("smith\"exam1\"test.txt");
D、System.out.println("smith"\exam1"\test.txt");

28、有如下代码: Class a extends Thread{ Public void run{ For(int i=1;i<100;i++){ System.out.println(i);} }} 能正确启动a中run方法的是()
A、a.run();
B、a a1=new a(); a1.run();
C、a a1=new a(); a1.start();
D、a a1=new a(); Thread t=new Thread(a); a.start();

29、Which of the following is the correct expression of character 4?
A、4
B、"4"
C、'4'
D、'\0004'

30、程序如下: public class Borley extends Thread { public static void main(String[] argv) { Borley b = new Borley(); b.start(); } public void run() { System.out.println("Running"); } } 下面描述正确的是()。
A、通过编译和运行但是没有任何输出
B、通过编译,运行后输出"Running"
C、编译出错,没有线程可供运行
D、编译出错,没有权限使用Thread

复习测验3

1、Which of the following statements are true?()
A、The wait(), notify(), and notifyAll() methods must be invoked from a synchronized method or a synchronized block.
B、When wait() is invoked, it pauses the thread and releases the lock on the object simultaneously. When the thread is restarted after being notified, the lock is automatically reacquired.
C、The notify() method can wake only one waiting thread.
D、An exception would occur if no thread is waiting on the object when the notify() method is invoked on the object.

2、Which of the following statements are NOT true?
A、A method in an interface must not have a body
B、A class may extend one other class plus at most one interface
C、A class may extends at most one other class plus implement many interfaces
D、An class accesses an interface via the keyword implements

3、Which of the following statements are not true
A、A default constructor is provided automatically if no constructors are explicitly declared in the class
B、At least one constructor must always be defined explicitly
C、The default constructor is a no-arg constructor
D、A default constructor always exist in class

4、Which of the following declares an abstract method in an abstract Java class?
A、public abstract method();
B、public abstract void method();
C、public void abstract Method();
D、public abstract void method() { }

5、Which of the following class definitions defines a legal abstract class?
A、class A { abstract void unfinished() { } }
B、class A { abstract void unfinished(); }
C、abstract class A { abstract void unfinished(); }
D、public class abstract A { abstract void unfinished(); }

6、Which of the following are not true.
A、A static method may be invoked before even a single instance of the class is constructed
B、A static method cannot access non-static methods of the class
C、Abstract modifier can appear before a class or a method but not before a variable
D、final modifier can appear before a class or a variable but not before a method

7、What will happen when you try compiling and running this code? public class Ref{ public static void main(String argv[]){ Ref r = new Ref(); r.amethod(r); } public void amethod(Ref r){ int i=99; multi(r); System.out.println(i); } public void multi(Ref r){ r.i = r.i*2; }}
A、Error at compile time
B、An output of 99
C、An output of 198
D、An error at runtime

8、What will happen when you compile and run the following code? public class Scope{ private int i; public static void main(String argv[]){ Scope s = new Scope(); s.amethod(); }//End of main public static void amethod(){ System.out.println(i); }//end of amethod }//End of class
A、A value of 0 will be printed out
B、Nothing will be printed out
C、A compile time error
D、A compile time error complaining of the scope of the variable i

9、What will happen when you attempt to compile and run the following code. public class Pvf{ static boolean Paddy; public static void main(String argv[]){ System.out.println(Paddy); } }
A、Compile time error
B、compilation and output of false
C、compilation and output of true
D、compilation and output of null

10、What will be the result of attempting to compile and run the 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 int[5]; for(i=0;i < ar.length;i++) System.out.println(ar[i]); }}
A、a sequence of 5 0's will be printed
B、Error: ar is used before it is initialized
C、Error Mine must be declared abstract
D、IndexOutOfBoundes Error

11、What modifier should you use on the members of a class so that they are not accessible to another class in a different package, but are accessible to any subclasses in any package?
A、public
B、private
C、protected
D、Use the default modifier

12、What modifier should you use on a class so that a class in the same package can access it but a class in a different package cannot access it?
A、public
B、private
C、protected
D、Use the default modifier

13、What is wrong in the following code? class TempClass { int i; public void TempClass(int j) { int i = j; } } public class C { public static void main(String[] args) { TempClass temp = new TempClass(2); } }
A、The program has a compilation error because TempClass does not have a default constructor
B、The program has a compilation error because TempClass does not have a constructor with an int argument
C、The program compiles fine, but it does not run because class C is not public
D、The program compiles and runs fine

14、What is the output of the following code: public class Test { public static void main(String[] args) { Object o1 = new Object(); Object o2 = new Object(); System.out.print((o1 == o2) + " " + (o1.equals(o2))); } }
A、false false
B、true true
C、false true
D、true false

15、What gets displayed on the screen when the following program is compiled and run. Select the one correct answer. protected class example { public static void main(String args[]) { String test = "abc"; test = test + test; System.out.println(test); } }
A、The class does not compile because the top level class cannot be protected
B、The program prints "abc"
C、The program prints "abcabc"
D、The program does not compile because statement "test = test + test" is illegal

16、Variables that are shared by every instances of a class are __________.
A、public variables
B、private variables
C、instance variables
D、class variables

17、To make a variable defined in a class accessible only to methods defined in the classes in same package, which of the following keyword should be used. Select the one correct answer
A、By using the keyword private before the variable
B、By using the keyword protected before the variable
C、By using the keyword public before the variable
D、The variable should not be preceded by any of the above mentioned keywords

18、Test类中合法的构造函数是
A、test() { }
B、Test() { }
C、void Test() { }
D、private final Test() { }

19、Select the one most appropriate answer. A top level class without any modifier is accessible to
A、any class
B、any class within the same package
C、any class within the same file
D、any subclass of this class

20、Given: class CardBoard { Short story = 200; CardBoard go(CardBoard cb) { cb = null; return cb; } public static void main(String[] args) { CardBoard c1 = new CardBoard(); CardBoard c2 = new CardBoard(); CardBoard c3 = c1.go(c2); c1 = null; // do Stuff } } When // doStuff is reached, how many objects are eligible for GC?
A、0
B、1
C、2
D、3

21、Given: 5. class A { void m() { System.out.println("outer"); } } 6. 7. public class TestInners { 8. public static void main(String[] args) { 9. new TestInners().go(); 10. } 11. void go() { 12. new A().m(); 13. class A { void m() { System.out.println("inner"); } } 14. } 15. class A { void m() { System.out.println("middle"); } } 16. } What is the result?
A、inner
B、outer
C、middle
D、Compilation fails

22、Given: 3. public class Tour { 4. public static void main(String[] args) { 5. Cathedral c = new Cathedral(); 6. // insert code here 7. s.go(); 8. } 9. } 10. class Cathedral { 11. class Sanctum { 12. void go() { System.out.println("spooky"); } 13. } 14. } Which, inserted independently at line 6, compile and produce the output "spooky"?
A、Sanctum s = c.new Sanctum();
B、c.Sanctum s = c.new Sanctum();
C、c.Sanctum s = Cathedral.new Sanctum();
D、Cathedral.Sanctum s = c.new Sanctum();

23、Given: 3. public class Navel { 4. private int size = 7; 5. private static int length = 3; 6. public static void main(String[] args) { 7. new Navel().go(); 8. } 9. void go() { 10. int size = 5; 11. System.out.println(new Gazer().adder()); 12. } 13. class Gazer { 14. int adder() { return size * length; } 15. } 16. } What is the result?
A、15
B、21
C、An exception is thrown at runtime
D、Compilation fails due to multiple errors

24、Given: 1. // insert code here 2. class StatTest { 3. public static void main(String[] args) { 4. System.out.println(Integer.MAX_VALUE); 5. } 6. } Which, inserted independently at line 1, compiles?
A、import static java.lang;
B、import static java.lang.Integer;
C、import static java.lang.Integer.*;
D、import static java.lang.Integer.*_VALUE;

25、Given two files: 1. package pkgA; 2. public class Foo { 3. int a = 5; 4. protected int b = 6; 5. public int c = 7; 6. } 3. package pkgB; 4. import pkgA.*; 5. public class Baz { 6. public static void main(String[] args) { 7. Foo f = new Foo(); 8. System.out.print(" " + f.a); 9. System.out.print(" " + f.b); 10.System.out.print(" " + f.c); 11. } 12. } What is the result?
A、5 6 7
B、5 followed by an exception
C、Compilation fails with an error on line 7
D、Compilation fails with an error on line 8 and line 9

26、Given the following code public class Sytch{ int x=2000; public static void main(String argv[]){ System.out.println("Ms "+argv[1]+"Please pay $"+x); } } What will happen if you attempt to compile and run this code with the command line java Sytch Jones Diggle
A、Compilation and output of Ms Diggle Please pay $2000
B、Compile time error
C、Compilation and output of Ms Jones Please pay $2000
D、Compilation but runtime error

27、Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate?
A、x contains an array of ten int values
B、x contains an array of ten objects of the Circle type
C、x contains a reference to an array and each element in the array can hold a reference to a Circle object
D、x contains a reference to an array and each element in the array can hold a Circle object

28、Given the declaration Circle x = new Circle(), which of the following statement is most accurate.
A、x contains an int value
B、x contains an object of the Circle type
C、x contains a reference to a Circle object
D、You can assign an int value to x

29、Assume java.util.Date[] dates = new java.util.Date[10], which of the following statements are true?
A、dates is null
B、dates[0] is null
C、dates = new Date() is fine, which creates a new Date object and assigns to dates
D、dates = new java.util.Date[5] is wrong

30、Given two reference variables t1 and t2, if t1.equals(t2) is true, t1 == t2 ____
A、is always false
B、is always true
C、may be true or false
D、i don't know

复习测验4

1、Analyze the following code: public class Test { public static void main(String args[]) { NClass nc = new NClass(); nc.t = nc.t++; } } class NClass { int t; private NClass() { } }
A、The program has a compilation error because the NClass class has a private constructor
B、The program does not compile because the parameter list of the main method is wrong
C、The program compiles, but has a runtime error because t has no initial value
D、The program compiles and runs fine

2、Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } }
A、The variable t is not initialized and therefore causes errors
B、The variable t is private and therefore cannot be accessed in the main method
C、t is non-static and it cannot be referenced in a static context in the main method
D、The variable x is not initialized and therefore causes errors

3、Analyze the following code: class Circle { private double radius; public Circle(double radius) { radius = radius; } }
A、The program has a compilation error because it does not have a main method
B、The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0
C、The program has a compilation error because you cannot assign radius to radius
D、The program does not compile because Circle does not have a default constructor

4、Analyze the following code and choose the best answer: public class Foo { private int x; public static void main(String[] args) { Foo foo = new Foo(); System.out.println(foo.x); } }
A、Since x is private, it cannot be accessed from an object foo
B、Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code
C、Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code
D、You cannot create a self-referenced object; that is, foo is created inside the class Foo

5、A top level class may have only the following access modifier. Select the one correct answer
A、friendly
B、private
C、protected
D、public

6、8、 给出下面的代码段 public class Base{ int x, y; static int z; public Base(int a,int b) { x=a; y=b; } } 以下代码错误的是?【 】
A、Base b=new Base(); b.z=10;
B、Base b=new Base(1,2); b.z=10;
C、Base.z=10;
D、Base b=new Base(1,2); b.x=2;

7、6、 已知如下类说明 public class Test { private float f = 1.0; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); ____________________________. } } 在空格处如下哪个使用是错误的?【 】
A、t.f
B、this.m
C、t.m
D、n

8、下以下哪个类能正确编译?【 】
A、class k{ abstract void b(){ } }
B、abstract class k{ void b(){ } }
C、abstract class k{ abstract void b(){ }}
D、abstract class k{ final abstract void b(); }

9、实现接口用哪个关键字【 】
A、interface
B、package
C、implements
D、extends

10、To prevent a class from being instantiated, ____________
A、don't use any modifiers on the constructor
B、use the public modifier on the constructor
C、use the private modifier on the constructor
D、use the static modifier on the constructor

11、public class Base{ int x; static int z; public Base() { z++;(1)} Public static void main(String[] args){ int y; Base b=new Base(); System.out.print(Base.z);(20) System.out.print(x);(3) System.out.print(y);(4) } } 会出错的语句是【 】
A、(1)
B、(2)
C、(3)
D、(4)

12、在Java中,能实现多重继承效果的方式是( )
A、内部类
B、适配器
C、接口
D、同步

13、成员变量的属性有private、public、缺省、protected四种,若类A中有一个成员变量为m,类B为A同一个包的子类,类C为A的不同包的子类,则变量m定义为( )属性,在B中能访问到m,但是在C中却访问不到。【 】
A、private
B、public
C、缺省
D、protected

14、编译并运行以下程序,以下描述哪个选项是正确的( ) 1: class X{ 2: protected String toString(){ 3: return super.toString();} 4: }
A、编译通过运行无异常
B、编译通过但运行时出错
C、行2出错,不能成功编译
D、不能成功编译,行3出错

15、Which statements are most accurate regarding the following classes? class A { private int i; protected int j; } class B extends A { private int k; protected int m; }
A、An object of B contains data fields i, j, k, m
B、An object of B contains data fields j, k, m
C、An object of B contains data fields j, m
D、An object of B contains data fields k, m

16、Which of the following statements are true?
A、Methods cannot be overriden to be more private
B、static methods cannot be overloaded
C、private methods cannot be overloaded
D、An overloaded method cannot throw exceptions not checked in the base class

17、Which of the following statements are true?
A、A method cannot be overloaded to be less public in a child class
B、To be overridden a method only needs the same name and parameter types
C、To be overridden a method must have the same name, parameter and return types
D、An overridden method must have the same name, parameter names and parameter types

18、Which of the following statements are true?
A、Static methods cannot be overriden to be non static
B、Static methods cannot be declared as private
C、Private methods cannot be overloaded
D、An overloaded method cannot throw exceptions not checked in the base class

19、Which of the following statements are true
A、constructors cannot be overloaded
B、constructors cannot be overridden
C、a constructor can return a primitive or an object reference
D、constructor code executes from the current class up the hierarchy to the ancestor class

20、Which of the following classes cannot be extended?
A、class A { }
B、class A { private A();}
C、final class A { }
D、class A { protected A();}

21、Which is true?
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

22、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[]){ 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 looove it

23、What will happen when you attempt to compile and run the following code? class Base{ Base(){ System.out.println("Base"); } } public class Checket extends Base{ public static void main(String argv[]){ Checket c = new Checket(); super(); } Checket(){ System.out.println("Checket"); } }
A、Compile time error
B、Checket followed by Base
C、Base followed by Checket
D、runtime error

24、What will happen when you attempt to compile and run the following code class Base{ public void Base(){ System.out.println("Base"); } } public class In extends Base{ public static void main(String argv[]){ In i=new In(); } }
A、Compile time error Base is a keyword
B、Compilation and no output at runtime
C、Output of Base
D、Runtime error Base has no valid constructor

25、What will happen when you attempt to compile and run the following code class Base{ private void amethod(int iBase){ System.out.println("Base.amethod"); }}class Over extends Base{ public static void main(String argv[]){ Over o = new Over(); int iBase=0; o.amethod(iBase); } public void amethod(int iOver){ System.out.println("Over.amethod"); }}
A、Compile time error complaining that Base.amethod is private
B、Runtime error complaining that Base.amethod is private
C、Output of "Base.amethod"
D、Output of "Over.amethod"

26、What will happen when you attempt to compile and run the following class? 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"

27、What is the output of running class C? class A { public A() { System.out.println( "The default constructor of A is invoked"); } } class B extends A { public B() { System.out.println( "The default constructor of B is invoked"); } } public class C { public static void main(String[] args) { B b = new B(); } }
A、Nothing displayed
B、"The default constructor of B is invoked"
C、"The default constructor of A is invoked""The default constructor of B is invoked"
D、"The default constructor of B is invoked""The default constructor of A is invoked"

28、Suppose you create a class Cylinder to be a subclass of Circle. Analyze the following code: class Cylinder extends Circle { double length; Cylinder(double radius) { Circle(radius); } }
A、The program compiles fine, but you cannot create an instance of Cylinder because the constructor does not specify the length of the cylinder
B、The program has a compile error because you attempted to invoke the Circle class's constructor illegally
C、The program compiles fine, but it has a runtime error because of invoking the Circle class's constructor illegally
D、The program compiles and run fine

29、Object-oriented programming allows you to derive new classes from existing classes. This is called ________
A、encapsulation
B、inheritance
C、abstraction
D、generalization

30、下面说法正确的是?
A、一个子类可以有多个父类,一个父类也可以有多个子类
B、一个子类可以有多个父类,但一个父类只可以有一个子类
C、一个子类可以有一个父类,但一个父类可以有多个子类
D、上述说法都不对

复习测验5

1、Inheritance means _______
A、that data fields should be declared private
B、that a class can extend another class
C、that a variable of supertype can refer to a subtype object
D、that a class can contain another class

2、Given: public abstract interface Frobnicate { public void twiddle(String s); } Which is a correct class?
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) { } }

3、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

4、Given: 3. class Building { 4. Building() { System.out.print("b "); } 5. Building(String name) { 6. this(); System.out.print("bn " + name); 7. } 8. } 9. public class House extends Building { 10. House() { System.out.print("h "); } 11. House(String name) { 12. this(); System.out.print("hn " + name); 13. } 14. public static void main(String[] args) { new House("x "); } 15. } What is the result?
A、h hn x
B、hn x h
C、b h hn x
D、b hn x h

5、Given: 3. class Alpha { 4. static String s = " "; 5. protected Alpha() { s += "alpha "; } 6. } 7. class SubAlpha extends Alpha { 8. private SubAlpha() { s += "sub "; } 9. } 10. public class SubSubAlpha extends Alpha { 11. private SubSubAlpha() { s += "subsub "; } 12. public static void main(String[] args) { 13. new SubSubAlpha(); 14. System.out.println(s); 15. } 16. } What is the result?
A、subsub
B、sub subsub
C、alpha subsub
D、alpha sub subsub

6、Given: 1. public class Electronic implements Device 2.{ public void doIt() { } } 3. abstract class Phone1 extends Electronic { } 5. abstract class Phone2 extends Electronic 6.{ public void doIt(int x) { } } 7. class Phone3 extends Electronic implements Device 8.{ public void doStuff() { } } 9. interface Device { public void doIt(); } What is the result?
A、Compilation succeeds
B、Compilation fails with an error on line 1
C、Compilation fails with an error on line 3
D、Compilation fails with an error on line 5

7、Given: 1. public abstract class Shape { 2. private int x; 3. private int y; 4. public abstract void draw(); 5. public void setAnchor(int x, int y) { 6. this.x = x; 7. this.y = y; 8. } 9. } Which class use the Shape class correctly?
A、public class Circle implements Shape { private int radius;}
B、public abstract class Circle extends Shape { private int radius; }
C、public class Circle extends Shape { private int radius; public void draw(); }
D、public abstract class Circle implements Shape { private int radius; public void draw(); }

8、Given the following code how could you invoke the Base constructor that will print out the string "base constructor"; class Base{ Base(int i){ System.out.println("base constructor"); } Base(){ } } public class Sup extends Base{ public static void main(String argv[]){ Sup s= new Sup(); //One } Sup() { //Two } public void derived() { //Three }}
A、On the line After //One put Base(10);
B、On the line After //One put super(10);
C、On the line After //Two put super(10);
D、On the line After //Three put super(10);

9、Analyze the following code: public class Test { public static void main(String[] args) { B b = new B(); b.m(5); System.out.println("i is " + b.i); } } class A { int i; public void m(int i) { this.i = i; } } class B extends A { public void m(String s) { } }
A、The program has a compilation error, because m is overridden with a different signature in B
B、The program has a compilation error, because b.m(5) cannot be invoked since the method m(int) is hidden in B
C、The program has a runtime error on b.i, because i is not accessible from b
D、The method m is not overridden in B. B inherits the method m from A and defines an overloaded method m in B

10、一个JAVA类最多可以继承的父类个数为【 】个
A、1
B、2
C、3
D、多个

11、给出下面的代码段 class b { int n=1; void disp(){ System.out.print (n); } } class c extends b { int n=2; void disp(){ super.disp(); System.out.print(super.n); System.out.print(n); } public static void main(String[] args) { (new c()).disp(); } }; 运行结果哪项是正确的?【 】
A、112
B、222
C、111
D、221

12、在 Java 中,所有类的根类是( )
A、java.lang.Object
B、java.lang.Class
C、java.applet.Applet
D、java.awt.Frame

13、以下哪项是接口的正确定义?
A、interface B { void print() { } ;}
B、abstract interface B { void print() ;}
C、abstract interface B extends A1,A2 //A1、A2为已定义的接口 { abstract void print(){ };}
D、interface B { void print();}

14、下面是People和Child类的定义和构造方法,每个构造方法都输出编号。在执行new Child("mike")的时候都有哪些构造方法被顺序调用?请选择输出结果 ( ) class People { String name; public People() { System.out.print(1); } public People(String name) { System.out.print(2); this.name = name; } } class Child extends People { People father; public Child(String name) { System.out.print(3); this.name = name; father = new People(name + ":F"); } public Child(){ System.out.print(4); } }
A、312
B、32
C、13
D、132

15、出下面的代码__ _______ __。 class Person{ String name,department; public void printValue(){ System.out.println(“name is”+name); } } public class Teacher extends Person{ int salary; public void printValue(){ _______________________ System.out.println(“salary is”+ salary); } } 下面的哪个表达式可以加入到Teacher类的printValue()方法中。______
A、printValue();
B、this.printValue();
C、person.printValue();
D、super.printValue();

16、8、 有如下代码: //A.java class A { int x; public A(int x){ this.x=x;} } //B.java class B extends A{ String name; public B(String name){ x=10; this.name=name; } public static void main(String[] args){ B b=new B("tom"); System.out.println(b.name +b.x); } } 以下说法正确的是【 】
A、编译B通过,运行B,输出:tom10;
B、编译B通过,运行B失败,因为b.name +b.x中字符串不能与整型相加
C、编译B失败,因为b.name +b.x中字符串不能与整型相加
D、编译B失败,因为A中没有无参构造函数

17、Analyze the following code.the correct answer is () // Test.java: Define threads using the Thread class import java.util.*; public class Test { private Stack stack = new Stack(); private int i = 0; /** Main method */ public static void main(String[] args) { new Test(); } public Test() { // Start threads new Producer().start(); new Consumer().start(); } class Producer extends Thread { public void run() { while (true) { System.out.println("Producer: put " + i); stack.push(new Integer(i++)); synchronized (stack) { notifyAll(); } } } } class Consumer extends Thread { public void run() { while (true) { synchronized (stack) { try { while (stack.isEmpty()) stack.wait(); System.out.println("Consumer: get " + stack.pop()); } catch (InterruptedException ex) { ex.printStackTrace(); } } } } } }
A、The program creates two threads: one to add data to the stack and the other to get data from the stack.
B、The program has a compilation error on the notifyAll() method in the Producer class because it is not invoked from the stack object.
C、The program will throw an exception because the notifyAll() method in the Producer class is not invoked from the stack object.
D、The program has a logic error because the lock obtained by the synchronized block for notifyAll in the Producer class is stack and it should be this (i.e., synchronized (this) { notifyAll(); }).

18、看下面一段程序:   class Aclass{    void go(){     System.out.println("Aclass");    }   }   public class Bclass extends Aclass{    void go{     System.out.println("Bclass");    }   public static void main(String args[]){    Aclass a=new Aclass();    Aclass a1=new Bclass();   a.go();   a1.go();   } 以上程序运行结果是:
A、Aclass Aclass
B、Aclass Bclass
C、Bclass Aclass
D、Bclass Bclass

19、假设类A是类B的父类,下列声明对象x的语句中不正确的是
A、A x=new A();
B、A x=new B();
C、B x=new B();
D、B x=new A();

20、What is the output of the following code? public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends Person { public String getInfo() { return "Student"; } } class Person { public String getInfo() { return "Person"; } public void printPerson() { System.out.println(getInfo()); } }
A、Person Person
B、Person Student
C、Stduent Student
D、Student Person

21、Polymorphism means ___________
A、that data fields should be declared private
B、that a class can extend another class
C、that a variable of supertype can refer to a subtype object
D、that a class can contain another class

22、In implementing two classes Employee and Manager, such that each Manager is an Employee, what should be the relationship between these classes. Select the one correct answer
A、Employee should be the base class of Manager class
B、Manager should be the base class of Employee class
C、Manager class should include the Employee class as a data member
D、Employee class should include Manager class as a data member

23、Given: 1. class Foo { 2. public int a = 3; 3. public void addFive() { a += 5; System.out.print("f "); } 4. } 5. class Bar extends Foo { 6. public int a = 8; 7. public void addFive() { this.a += 5; System.out.print("b " ); } 8. } Invoked with: Foo f = new Bar(); f.addFive(); System.out.println(f.a); What is the result?
A、b 3
B、b 8
C、b 13
D、f 3

24、Given the following code class Base { } class Agg extends Base{ public String getFields(){ String name = "Agg"; return name; } } public class Avf{ public static void main(String argv[]){ Base a = new Agg(); //Here } } What code placed after the comment //Here will result in calling the getFields method resulting in the output of the string "Agg"?
A、System.out.println(a.getFields());
B、System.out.println(a.name);
C、System.out.println((Base) a.getFields());
D、System.out.println( ((Agg) a).getFields());

25、A派生出子类B,B派生出子类C,并且在Java源代码中有如下声明: 1. A a0=new A(); 2. A a1 =new B(); 3. A a2=new C(); 问以下哪个说法是正确的?
A、只有第1行能通过编译
B、第1、2行能通过编译,但第3行编译出错
C、第1、2、3行能通过编译,但第2、3行运行时出错
D、第1行、第2行和第3行的声明都是正确的

26、使用下列哪个布局管理器时,当frame的大小变化时,在frame上的按钮的位置会发生变化?
A、BorderLayout
B、FlowLayout
C、CardLayout
D、GridLayout

27、A Button is positioned in a Frame. Only height of the Button is affected by the Frame while the width is not. Which layout manager should be used?
A、FlowLayout
B、CardLayout
C、North and South of BorderLayout
D、East and West of BorderLayout

28、Given a List using a proportional pitch font and constructed like this: List l=new List(5,true); Which statement is true?
A、The displayed item exactly five lines unless otherwise constrained
B、The displayed item is five lines init, but can displayed more than five Item by scroll
C、The maximum number of item in a list will be five.
D、The list is multiple mode

29、What is the return value of the method in the event listener interface?
A、int
B、String

学习通Java语言程序设计E

Java语言是当前比较流行的编程语言之一,其具有代码可移植性强、安全性高以及跨平台等优点,成为很多企业和个人开发者的首选语言。学习Java语言程序设计E可以帮助学生建立起Java编程的基础知识,掌握Java编程语言的语法和基本编程思想,为日后的Java开发工作打下坚实的基础。

课程重点

学习通Java语言程序设计E的重点包括以下几个方面:

  1. Java编程语言概述:包括Java语言的历史、特点以及应用领域等;
  2. Java基础语法:包括Java变量、数据类型、运算符、控制语句、数组等;
  3. 面向对象编程基础:包括面向对象编程的思想、类、对象、封装、继承、多态等;
  4. Java高级特性:包括异常处理、泛型、集合框架、IO操作、多线程等;
  5. Java GUI编程:包括Swing组件、AWT组件、事件处理等。

课程特点

学习通Java语言程序设计E的特点是:

  1. 理论与实践相结合:课程内容理论基础与实际应用相结合,让学生能够理解Java编程语言的基本原理与应用场景;
  2. 重点突出、难点讲解:深入浅出地讲解Java编程中的难点和重点,帮助学生快速掌握Java编程语言的核心知识;
  3. 案例实战:通过案例实战,让学生掌握Java编程语言在实际开发过程中的应用技巧;
  4. 课后习题:每个章节都有丰富的习题,帮助学生巩固所学知识,掌握Java编程语言的应用技巧。

课程收获

学习通Java语言程序设计E的收获包括:

  1. 掌握Java编程语言的基本语法和编程思想;
  2. 了解Java编程语言的应用场景和优势;
  3. 掌握面向对象编程的基本思想和应用技巧;
  4. 掌握Java编程语言的高级特性和应用技巧;
  5. 掌握Java GUI编程的基本知识和应用技巧。

结语

学习通Java语言程序设计E是一门非常重要的课程,它不仅是Java编程语言的入门课程,更是学习Java编程的基础。学好这门课程可以帮助学生快速掌握Java编程语言的基本知识和应用技巧,为日后的Java开发工作打下坚实的基础。

学习通Java语言程序设计E

Java语言是当前比较流行的编程语言之一,其具有代码可移植性强、安全性高以及跨平台等优点,成为很多企业和个人开发者的首选语言。学习Java语言程序设计E可以帮助学生建立起Java编程的基础知识,掌握Java编程语言的语法和基本编程思想,为日后的Java开发工作打下坚实的基础。

课程重点

学习通Java语言程序设计E的重点包括以下几个方面:

  1. Java编程语言概述:包括Java语言的历史、特点以及应用领域等;
  2. Java基础语法:包括Java变量、数据类型、运算符、控制语句、数组等;
  3. 面向对象编程基础:包括面向对象编程的思想、类、对象、封装、继承、多态等;
  4. Java高级特性:包括异常处理、泛型、集合框架、IO操作、多线程等;
  5. Java GUI编程:包括Swing组件、AWT组件、事件处理等。

课程特点

学习通Java语言程序设计E的特点是:

  1. 理论与实践相结合:课程内容理论基础与实际应用相结合,让学生能够理解Java编程语言的基本原理与应用场景;
  2. 重点突出、难点讲解:深入浅出地讲解Java编程中的难点和重点,帮助学生快速掌握Java编程语言的核心知识;
  3. 案例实战:通过案例实战,让学生掌握Java编程语言在实际开发过程中的应用技巧;
  4. 课后习题:每个章节都有丰富的习题,帮助学生巩固所学知识,掌握Java编程语言的应用技巧。

课程收获

学习通Java语言程序设计E的收获包括:

  1. 掌握Java编程语言的基本语法和编程思想;
  2. 了解Java编程语言的应用场景和优势;
  3. 掌握面向对象编程的基本思想和应用技巧;
  4. 掌握Java编程语言的高级特性和应用技巧;
  5. 掌握Java GUI编程的基本知识和应用技巧。

结语

学习通Java语言程序设计E是一门非常重要的课程,它不仅是Java编程语言的入门课程,更是学习Java编程的基础。学好这门课程可以帮助学生快速掌握Java编程语言的基本知识和应用技巧,为日后的Java开发工作打下坚实的基础。