1. public class X {  2. public object m ()  {  3. object o =

题目
单选题
1. public class X {  2. public object m ()  {  3. object o = new float (3.14F);  4. object [] oa = new object [1]; 5. oa[0]= o;  6. o = null;  7. oa[0] = null;  10. return o;  9. }  10. }  When is the float object created in line 3, eligible for garbage collection?()
A

 Just after line 5.

B

 Just after line 6.

C

 Just after line 7.

D

 Just after line 8(that is, as the method returns).

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Given:Which method will complete this class?()

A.public int compareTo(Object o){/*more code here*/}

B.public int compareTo(Score other){/*more code here*/}

C.public int compare(Score s1,Score s2){/*more code here*/}

D.public int compare(Object o1,Object o2){/*more code here*/}


参考答案:B

第2题:

public class X {  public object m () {   object o = new float (3.14F);   object oa = new object [1];   oa[0]= o;   o = null;   return oa[0];   }   }   When is the float object created in line 3, eligible for garbage collection?()

  • A、 Just after line 5
  • B、 Just after line 6
  • C、 Just after line 7 (that is, as the method returns)
  • D、 Never in this method.

正确答案:D

第3题:

阅读下列函数说明和Java代码,将应填入(n)处的字句写在对应栏内。

【说明】

类Queue表示队列,类中的方法如下表所示。

类Node表示队列中的元素;类EmptyQueueException给出了队列操作中的异常处理操作。

public class TestMain { //主类

public static viod main (String args[]){

Queue q=new Queue();

q.enqueue("first!");

q.enqueue("second!");

q.enqueue("third!");

(1) {

while(true)

System.out.println(q.dequeue());

}

catch( (2) ){ }

}

public class Queue { //队列

Node m_FirstNode;

public Queue(){m_FirstNode=null;}

public boolean isEmpty(){

if(m_FirstNode==null)return true;

else return false;

}

public viod enqueue(Object newNode) { //入队操作

Node next=m_FirstNode;

if(next==null)m_FirstNode=new Node(newNode);

else{

while(next.getNext()!=null)next=next.getNext();

next.setNext(new node(newNode));

}

}

public Object dequeue() (3) { //出队操作

Object node;

if (isEempty())

(4); //队列为空, 抛出异常

else{

node=m_FirstNode.getObject();

m_FirstNode=m_FirstNode.getNext();

return node;

}

}

}

public class Node{ //队列中的元素

Object m_Data;

Node m_Next;

public Node(Object data) {m_Data=data; m_Next=null;}

public Node(Object data, Node next) {m_Data=data; m_Next=-next;}

public void setObject(Object data) {m_Data=data;}

public Object getObject(Object data) {return m_data;}

public void setNext(Node next) {m_Next=next;}

public Node getNext() {return m_Next;}

}

public class EmptyQueueException extends (5) { //异常处理类

public EmptyQueueException() {

System.out.println("队列已空! ");

}

}


正确答案:(1)try (2)Exception e或者EmptyQueueException e (3)throw EmptyQueueException (4)throw(new EmptyQueueException()) (5)Exception
(1)try (2)Exception e或者EmptyQueueException e (3)throw EmptyQueueException (4)throw(new EmptyQueueException()) (5)Exception 解析:(1)try
从紧随其后的catch可以断定这是异常处理的try-catch结构。
(2)Exception e或者EmptyQueueException e
其中e是对象名,可用任意合法标识符替换,这是catch要捕获的信息。
(3)throw EmptyQueueException
当队列为空时,抛出错误信息EmptyQueueException。
(4)throw(new EmptyQueueException())
当队列为空时,抛出异常。动态生成EmptyQueueException对象,出错处理。
(5)Exception
EmptyQueueException对象是从异常处理类Exception扩展而来。

第4题:

1. public class X (  2. public object m ()  {  3. object o = new float (3.14F);  4. object [] oa = new object [1];  5. oa[0]= o;  6. o = null;  7. return oa[0];  8. }  9. }   When is the float object created in line 3, eligible for garbage collection?()  

  • A、 Just after line 5
  • B、 Just after line 6
  • C、 Just after line 7 (that is, as the method returns)
  • D、 Never in this method.

正确答案:D

第5题:

1. import java.util.*;  2. class ForInTest {  3. static List list = new ArrayList();  4.  5. static List getList() { return list; }  6.  7. public static void main(String [] args) {  8. list.add("a"); list.add("b"); list.add("c");  9. // insert code here  10. System.out.print(o);  11. }  12. } 第 9 行插入哪一项将输出 abc?() 

  • A、for(char o: list)
  • B、for(Object o: getList())
  • C、for(Object o: getList();)
  • D、for(Object o: o.getList())

正确答案:B

第6题:

阅读以下说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。

说明

类Queue表示队列,类中的方法如下表所示。

类Node表示队列中的元素;类EmptyQueueException 给出了队列操作中的异常处理操作。

Java 代码

public class TestMain{ // 主类

public static void main(String args[]) {

Queue q = new Queue();

q.enqueue("first!");

q.enqueue("second!");

q.enqueue("third!");

(1) {

while(true)

System.out.println(q. dequeue());

}

catch((2)) ( }

}

}

public class Queue { // 队列

Node m_FirstNode;

public Queue() { m_FirstNode = null; }

public boolean isEmpty() {

if(m_FirstNode == null) return true;

else return false;

}

public void enqueue(Object newNode) {// 入队操作

Node next = m_FirstNode;

if(next==null) m_FirstNode = new Node(newNode);

else {

while(next.getNext() != null) next = next.getNext();

next.setNext(new Node(newNode));

}

}

public Object dequeue() (3) {// 出队操作

Object node;

if (isEmpty())

(4); // 队列为空,抛出异常

else {

node = m_FirstNode.getObject();

m_FirstNode = m_FirstNode.getNext();

return node;

}

}

}

public class Node { // 队列中的元素

Object m_Data;

Node m_Next;

public Node(Object data) { m_Data = data; m_Next = null; }

public Node(Object data, Node next) { m_Data = data; m_Next = next; }

public void setObject(Object data) { m_Data = data; }

public Object getObject0 { return m_Data; }

public void setNext(Node next) { m_Next = next; }

public Node getNext() { return m_Next; }

}

public class EmptyQueueException extends (5) { // 异常处理类

public EmptyQueueException0 {

System.out.println("队列已空 ! ");

}

}


正确答案:(1)try (2)EmptyQueueException e (3)throws EmpbtyQUeUeExCeption (4)throw(new EmptyQueueException()) (5)Exception
(1)try (2)EmptyQueueException e (3)throws EmpbtyQUeUeExCeption (4)throw(new EmptyQueueException()) (5)Exception 解析:本题以队列为例,考查Java的异常处理机制。
异常是指程序执行期间中断指令的正常流程的事件。当一个方法中发生错误时,此方法创建一个对象并将它交给运行时系统,此对象被称为异常对象。它包含关于错误的信息,包括错误的类型和错误发生时程序的状态。创建异常对象并将它交给运行时系统被称为抛出二个异常。
(Java运行时系统要求方法必须捕获或者指定它可以抛出的所有被检查的异常。)
▲捕获。方法可以通过为某类型的异常提供异常处理器来捕获异常。
▲指定。方法通过在它的声明块中使用throws子句(throws异常类型)指定它可以抛出异常。
▲被检查的异常。存在两种异常:运行时异常和非运行时异常。运行时异常在Java运行时系统内发生,如算术异常、指针异常等。方法不必捕获或指定运行时异常。非运行时异常是在Java运行时系统外的代码中发生的异常。编译器确保非运行时异常被捕获或指定,因此它们也被称为“被检查的异常”。
▲方法可以抛出的异常。包括:方法用throw语句直接抛出的任何异常;通过调用另一个方法间接抛出的任何异常。
try块和catch块是异常处理器的两个组件。在try块中产生的异常通常被紧跟其后的catch块指定的处理器捕获:
try{
可能抛出异常的语句
}
catch(异常类型异常引用){
处理异常的语句
}
在选择要抛出的异常的类型时,可以使用其他人编写的异常类,也可以编写自己的异常类。本题中采用自定义的类作为异常的类型。
本题中主类TestMain包含了异常处理机制,用于检测在出队时“队列为空”的错误。根据上面的描述,很容易得出第(1)空应填try。第(2)空应填写对相应异常类型的引用。由程序的注释可以得到,类EmptyQueueException是进行异常处理的类,因此第(2)空应填EmptyQueueException e(e为引用名)。由于异常都是从超类Exception派生而来的,因此第(5)空应填Exception。
由主类TestMain可以看到,在try块的内部并没有给出显示的抛出异常语句,即没有出现throw语句。由此可以得出,在类Queue的方法dequeue中必定要抛出异常。因此首先应指定方法dequeue可以抛出异常,则第(3)空应填throws EmptyQueueException。
由dequeue方法的注释可以看出,第(4)空应该是使用throw语句抛出异常。throw语
句需要—个参数:—个可抛出的对象。因此第(4)空应填throw(newEmptyQueueException())。

第7题:

1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() 

  • A、 Compilation will succeed for all classes and interfaces.
  • B、 Compilation of class C will fail because of an error in line 2.
  • C、 Compilation of class C will fail because of an error in line 6.
  • D、 Compilation of class AImpl will fail because of an error in line 2.

正确答案:C

第8题:

Given:Which two, inserted at line 11, will allow the code to compile?()

A.public class MinMax<?> {

B.public class MinMax<? extends Number> {

C.public class MinMax<N extends Object> {

D.public class MinMax<N extends Number> {

E.public class MinMax<? extends Object> {

F.public class MinMax<N extends Integer> {


参考答案:D, F

第9题:

下列代码正确的是哪项?() 

  • A、 public class Session implements Runnable, Clonable{   public void run ();public Object clone () ; }
  • B、 public class Session extends Runnable, Cloneable {  public void run() {/*dosomething*/}       public Object clone() {/*make a copy*/} }
  • C、 public abstract class Session implements Runnable, Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}        }
  • D、 public class Session implements Runnable, implements Clonable {       public void run() {/*do something*/}       public Object clone() {/*make a copy*/}       }

正确答案:C

第10题:

public class Test {  public static void main(String args[]) {  class Foo {  public int i = 3; }  Object o = (Object)new Foo();   Foo foo = (Foo)o;  System.out.println(“i = “ + foo.i); }  }  What is the result?()  

  • A、 i = 3
  • B、 Compilation fails.
  • C、 A ClassCastException is thrown at line 6.
  • D、 A ClassCastException is thrown at line 7.

正确答案:A

更多相关问题