Just after line 5.
Just after line 6.
Just after line 7.
Just after line 8(that is, as the method returns).
第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("队列已空 ! ");
}
}
第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?()
第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?()
第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?()
第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?()
第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?()
第7题:
Just after line 5.
Just after line 6.
Just after line 7.
Just after line 8(that is, as the method returns).
第8题:
Line5
Line6
Line7
Line8
Line9
Line10
第9题:
public class Session implements Runnable, Clonable{ public void run ();public Object clone () ; }
public class Session extends Runnable, Cloneable { public void run() {/*dosomething*/} public Object clone() {/*make a copy*/} }
public abstract class Session implements Runnable, Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
public class Session implements Runnable, implements Clonable { public void run() {/*do something*/} public Object clone() {/*make a copy*/} }
第10题:
It can be any class.
No class has access to base.
The class must belong to the geometry package.
The class must be a subclass of the class Hypotenuse.
第11题:
Just after line 5
Just after line 6
Just after line 7 (that is, as the method returns)
Never in this method.
第12题:
Line 5
Line 6
Line 7
Line 8
Line 9
Line 10
第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?()
第14题:
下列代码正确的是哪项?()
第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? ()
第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?()
第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?()
第18题:
Which three will compile and run without exception?()
第19题:
Just after line 5.
Just after line 6.
Just after line 7.
Just after line 8(that is, as the method returns).
第20题:
Tea
Coffee
Coffee Tea
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第21题:
Compilation will fail.
Compilation will succeed and the program will print “3”
Compilation will succeed but the program will throw a ClassCastException at line 6.
Compilation will succeed but the program will throw a ClassCastException at line 7.
第22题:
Just after line 5
Just after line 6
Just after line 7 (that is, as the method returns)
Never in this method.
第23题:
i = 3
Compilation fails.
A ClassCastException is thrown at line 6.
A ClassCastException is thrown at line 7.
第24题:
public int compareTo(Object o) {/*mode code here*/}
public int compareTo(Score other) {/*more code here*/}
public int compare(Score s1,Score s2){/*more code here*/}
public int compare(Object o1,Object o2){/*more code here*/}