10. public Object

题目

10. public Object m() { 11. Object o = new Float(3.14F); 12. Object [] oa = new Object[1]; 13. oa[0] = o; 14. o = null; 15. return oa[0]; 16. } When is the Float object, created in line 11, eligible for garbage collection?()  

  • A、 Just after line 13.
  • B、 Just after line 14.
  • C、 Never in this method.
  • D、 Just after line 15 (that is, as the method returns).
参考答案和解析
正确答案:C
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

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

第2题:

以下程序的输出结果是_____。 include class object {private:int val; public:objec

以下程序的输出结果是_____。

include<iostream.h>

class object

{ private:

int val;

public:

object( ) ;

object(int i) ;

~object( ) ;};

object: :object( )

{ val=0;

cout < < "Default constructor for object" < < endl;}

object: :object(int i)

{ val=i;

cout < < "Constructor for object" < < val < < endl;}

object: :~object( )

{ cout < < "Destructor for object" < < val < < endl;}

class container{ private:

object one;

object two;

int data;

public:

container( ) ;

container(int i,int j,int k) ;

~container( ) ;};

container: :container( )

{ data=0;

cout < < "Default constructor for container" < < endl;}

container: :container(int i,int j,int k) :two(i) ,one(j)

{ data=k;

cout < < "Constructor for container" < < endl;}

container: :~container( )

{ cout < < "Destructor for container" < < endl;}

void main( )

{ container anObj(5,6,10) ;}


正确答案:Constructor for object6 Constructor for object5 Constructor for container Destructor for container Destructor for object5 Destructor for object6
Constructor for object6 Constructor for object5 Constructor for container Destructor for container Destructor for object5 Destructor for object6 解析:C++语言中的构造函数和析构函数分别是在声明对象时和对象调用完毕后调用,本题中的调用就是这样成对出现的。

第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题:

在J2EE中,以下是firePropertyChange的原型,正确的是()。 

  • A、public void firePropertyChange(PropertyChangeListener l,String oldValue, String newValue)
  • B、public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
  • C、public void firePropertyChange(PropertyChangeSupport changes)
  • D、public void firePropertyChange(Object oldValue, Object newValue)

正确答案:B

第5题:

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

第6题:

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

第7题:

把一个对象写到一个流中相对比较简单,具体是通过调用ObjectOutputStream类的writeObject()方法实现的,那么该方法的定义为( )。

A.public final int writeObject(Object obj) throws IOException

B.public final void writeObject(Object obj) throws IOException

C.public Object writeObject(Object obj) throws IOException

D.public final Object writeObject(Object obj) throws IOException


正确答案:B
解析:writeObject()方法的正确定义为: public final void writeObject(Object Obj) throws IOException。即B选项的定义是正确的。

第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题:

在j2ee中,以下是firevetoablechange方法的正确的原型的是() 

  • A、public void fireVetoableChange(Object  oldValue,Object newValue)
  • B、 public void fireVetoableChange(String  propertyName,Object newValue)
  • C、 public void fireVetoableChange(String  propertyName, Object  oldValue ,Object newValue)throws PropertyVetoException
  • D、 public void fireVetoableChange(String  propertyName, Object  oldValue ,Object newValue)

正确答案:C

第10题:

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

更多相关问题