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

题目
单选题
public class X {   public object m () {   object o = new float (3.14F);   object oa = new object [1];   oa[0]= o;   o = null;   oa[0] = null;   return o;   }   }   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.阅读下列函数说明和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("队列已空! ");}}

更多“public class X {   public object m () {   object o = new flo”相关问题
  • 第1题:

    阅读以下说明和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())。

  • 第2题:

    1.public class GC{ 2.private Objec to; 3.private void doSomethingElse(Object obj){o=obj;} 4.public void doSomething(){ 5.Object o=new Object(); 6.doSomethingElse(o); 7.o=new Object(); 8.doSomethingElse(null); 9.o=null; 10.} 11.} When the doSomething method is called,after which line does the Object created in line 5 become available for garbage collection?()

    • A、Line5
    • B、Line6
    • C、Line7
    • D、Line8
    • E、Line9
    • F、Line10

    正确答案:D

  • 第3题:

    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

  • 第4题:

    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

  • 第5题:

    1.public class Test {  2.public static void main (String args[]) {  3.class Foo {  4.public int i = 3;  5.}  6.Object o = (Object) new Foo();  7.Foo foo = (Foo)o;  8.System.out.printIn(foo. i); 9. }  10.}   What is the result?()  

    • A、 Compilation will fail.
    • B、 Compilation will succeed and the program will print “3”
    • C、 Compilation will succeed but the program will throw a ClassCastException at line 6.
    • D、 Compilation will succeed but the program will throw a ClassCastException at line 7.

    正确答案:B

  • 第6题:

    public class X {   public object m () {   object o = new float (3.14F);   object oa = new object [1];   oa[0]= o;   o = null;   oa[0] = null;   return o;   }   }   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).

    正确答案:C

  • 第7题:

    单选题
    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).


    正确答案: D
    解析: 暂无解析

  • 第8题:

    单选题
    1.public class GC{ 2.private Objec to; 3.private void doSomethingElse(Object obj){o=obj;} 4.public void doSomething(){ 5.Object o=new Object(); 6.doSomethingElse(o); 7.o=new Object(); 8.doSomethingElse(null); 9.o=null; 10.} 11.} When the doSomething method is called,after which line does the Object created in line 5 become available for garbage collection?()
    A

    Line5

    B

    Line6

    C

    Line7

    D

    Line8

    E

    Line9

    F

    Line10


    正确答案: D
    解析: 暂无解析

  • 第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*/}       }


    正确答案: A
    解析: 暂无解析

  • 第10题:

    单选题
    package geometry;  public class Hypotenuse {  public InnerTriangle it = new InnerTriangle();  class InnerTriangle {  public int base;  public int height;  }  }  Which is true about the class of an object that can reference the variable base? ()
    A

     It can be any class.

    B

     No class has access to base.

    C

     The class must belong to the geometry package.

    D

     The class must be a subclass of the class Hypotenuse.


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    1. public class GC {  2. private Object o;  3. private void doSomethingElse(Object obj) { o = obj; }  4. public void doSomething() {  5. Object o = new Object();  6. doSomethingElse(o);  7. o = new Object();  8. doSomethingElse(null);  9.o=null;  10. }  11. }  When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection?()
    A

     Line 5

    B

     Line 6

    C

     Line 7

    D

     Line 8

    E

     Line 9

    F

     Line 10


    正确答案: E
    解析: 暂无解析

  • 第13题:

    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

  • 第14题:

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

    • 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

  • 第15题:

    package geometry;  public class Hypotenuse {  public InnerTriangle it = new InnerTriangle();  class InnerTriangle {  public int base;  public int height;  }  }  Which is true about the class of an object that can reference the variable base? ()

    • A、 It can be any class.
    • B、 No class has access to base.
    • C、 The class must belong to the geometry package.
    • D、 The class must be a subclass of the class Hypotenuse.

    正确答案:C

  • 第16题:

    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).

    正确答案:C

  • 第17题:

    public class Key {  private long id1;  private long 1d2;  // class Key methods  }  A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()

    • A、 public int hashCode()
    • B、 public boolean equals(Key k)
    • C、 public int compareTo(Object o)
    • D、 public boolean equals(Object o)
    • E、 public boolean compareTo(Key k)

    正确答案:A,D

  • 第18题:

    Which three will compile and run without exception?()

    • A、private synchronized Object o;
    • B、void go() {synchronized() { /* code here */ }
    • C、public synchronized void go() { /* code here */ }
    • D、private synchronized(this) void go() { /* code here */ }
    • E、void go() {synchronized(Object.class) { /* code here */ }
    • F、void go() {Object o = new Object();synchronized(o) { /* code here */ }

    正确答案:C,E,F

  • 第19题:

    单选题
    public class X {   public object m () {   object o = new float (3.14F);   object oa = new object [1];   oa[0]= o;   o = null;   oa[0] = null;   return o;   }   }   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).


    正确答案: A
    解析: 暂无解析

  • 第20题:

    单选题
    public class Drink implements Comparable {  public String name;  public int compareTo(Object o) {  return 0;  }  }  and:  Drink one = new Drink();  Drink two = new Drink();  one.name= “Coffee”;  two.name= “Tea”;  TreeSet set = new TreeSet();  set.add(one);  set.add(two);  A programmer iterates over the TreeSet and prints the name of each Drink object. What is the result?()
    A

     Tea

    B

     Coffee

    C

     Coffee Tea

    D

     Compilation fails.

    E

     The code runs with no output.

    F

     An exception is thrown at runtime.


    正确答案: B
    解析: 暂无解析

  • 第21题:

    单选题
    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.printIn(foo. i);  }   }   What is the result?()
    A

     Compilation will fail.

    B

     Compilation will succeed and the program will print “3”

    C

     Compilation will succeed but the program will throw a ClassCastException at line 6.

    D

     Compilation will succeed but the program will throw a ClassCastException at line 7.


    正确答案: D
    解析: 暂无解析

  • 第22题:

    单选题
    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.


    正确答案: A
    解析: 暂无解析

  • 第23题:

    单选题
    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.


    正确答案: D
    解析: 暂无解析

  • 第24题:

    单选题
    public class Score implements Comparable {  private int wins, losses;  public Score(int w, int 1) { wins = w; losses = 1; }  public int getWins() { return wins; }  public int getLosses() { return losses; }  public String toString() {  return “”; }  // insert code here  }  Which method will complete this class?()
    A

     public int compareTo(Object o) {/*mode 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
    解析: 暂无解析