在Spring中,下面的代码定义了一个前置通知类,则下列选项中,说法错误的是( )。public class LogAdvice implements MethodBeforeAdvice{
public void before(Method m,Object[]arges,Object target) throws Throwable{
System.out.println(m.getName()+"(" + Arrays.toString(args) +")";
});()
A. 方法before是MethodBeforeAdvice接口中定义的方法
B. 参数m是被通知的目标方法
C. 参数args是调用方法的参数
D. 参数target是代理类
第1题:
下列哪个方法可用于创建一个可运行的类? ( )
A.public class X implements Runable {public void run(){...,.,}}
B.public class X implements Thread {public void run(){......}}
C.public class X implements Thread {public int run(){……}}
D.public class X implements Runable {protected void run(){.....}}
第2题:
阅读以下技术说明和Java代码,将Java程序中(1)~(5)空缺处的语句填写完整。
[说明]
类Queue表示队列,类中的方法如表4-12所示。

类Node表示队列中的元素;类EmptyQueueException给出了队列中的异常处理操作。
[Java代码]
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 (is empty())
(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 ( "队列已空!" );
}
}
Java运行时系统要求方法必须捕获或者指定它可以抛出的所有被检查的异常如表4-16所示。
try块和catch块是异常处理器的两个组件。在try块中产生的异常通常被紧跟其后的catch块指定的处理器捕获。
try {
可能抛出异常的语句
}
catch(异常类型 异常引用) {
处理异常的语句
}
catch语句可以有多个分别处理不同类的例外。Java运行时系统从上到下分别对每个catch语句处理的例外类型进行检测直到找到类型相匹配的catch语句为止。其中类型匹配是指catch所处理的例外类型与生成的例外对象的类型完全一致或者是它的父类因此catch语句的排列顺序应该是从特殊到一般。也可以用一个catch语句处理多个例外类型此时它的例外类型参数应该是这几个例外类型的父类程序设计中要根据具体的情况来选择catch语句的例外处理类型。
在选择要抛出的异常的类型时可以使用其他人编写的异常类也可以编写自己的异常类。本试题中采用自定义的类作为异常的类型。
仔细阅读试题中给出的Java源代码可知主类TestMain包含了异常处理机制用于检测在出队时“队列为空”的错误。因此(1)空缺处所填写的内容是“try”。
由catch语句的语法可知(2)空缺处所填写的内容是对相应异常类型的引用。结合试题中给出的关键信息“类EmptyQueueException给出了队列操作中的异常处理操作”即类EmptyQueueException是进行异常处理的类因此(2)空缺处所填写的内容是“EmptyQueueExceptione”或者“Exceptione”其中e是对象名可用任意合法标识符替换。
由于异常都是从超类Exception派生而来的因此(5)空缺处所填写的内容是“Exception”。
仔细阅读主类TestMain程序段可以看到在try块的内部并没有给出显示的抛出异常语句即没有出现throw语句。结合(4)空缺处所在行的注释—“队列为空抛出异常”可以推断在类Queue的方法dequeue中必定要抛出异常。因此(3)空缺处应指定方法dequeue可以抛出异常即所填写的内容是“throws EmptyQueueException”。
(4)空缺处可以使用throw语句抛出异常而使用throw语句时需要一个参数即一个可抛出的对象因此(4)空缺处所填写的内容是“throw(new EmptyQueueException())”。
Java运行时系统要求方法必须捕获或者指定它可以抛出的所有被检查的异常,如表4-16所示。
try块和catch块是异常处理器的两个组件。在try块中产生的异常通常被紧跟其后的catch块指定的处理器捕获。
try {
可能抛出异常的语句
}
catch(异常类型 异常引用) {
处理异常的语句
}
catch语句可以有多个,分别处理不同类的例外。Java运行时系统从上到下分别对每个catch语句处理的例外类型进行检测,直到找到类型相匹配的catch语句为止。其中,类型匹配是指catch所处理的例外类型与生成的例外对象的类型完全一致或者是它的父类,因此,catch语句的排列顺序应该是从特殊到一般。也可以用一个catch语句处理多个例外类型,此时它的例外类型参数应该是这几个例外类型的父类,程序设计中要根据具体的情况来选择catch语句的例外处理类型。
在选择要抛出的异常的类型时,可以使用其他人编写的异常类,也可以编写自己的异常类。本试题中采用自定义的类作为异常的类型。
仔细阅读试题中给出的Java源代码可知,主类TestMain包含了异常处理机制,用于检测在出队时“队列为空”的错误。因此(1)空缺处所填写的内容是“try”。
由catch语句的语法可知,(2)空缺处所填写的内容是对相应异常类型的引用。结合试题中给出的关键信息“类EmptyQueueException给出了队列操作中的异常处理操作”,即类EmptyQueueException是进行异常处理的类,因此(2)空缺处所填写的内容是“EmptyQueueExceptione”,或者“Exceptione”,其中,e是对象名,可用任意合法标识符替换。
由于异常都是从超类Exception派生而来的,因此(5)空缺处所填写的内容是“Exception”。
仔细阅读主类TestMain程序段可以看到,在try块的内部并没有给出显示的抛出异常语句,即没有出现throw语句。结合(4)空缺处所在行的注释—“队列为空,抛出异常”可以推断,在类Queue的方法dequeue中必定要抛出异常。因此(3)空缺处应指定方法dequeue可以抛出异常,即所填写的内容是“throws EmptyQueueException”。
(4)空缺处可以使用throw语句抛出异常,而使用throw语句时需要一个参数,即一个可抛出的对象,因此(4)空缺处所填写的内容是“throw(new EmptyQueueException())”。
第3题:
阅读下列代码段,选出该代码段的正确的文件名( )。 class A { void method () { System.out.println ("methodl in class A"); } } public class B { void method2 () { System.out.println("method2 in class B"); } public static void main (String args[]) { System.out.println ("main () in class B"); } }
A.A.java
B.A.class
C.B.class
D.B.java
第4题:
阅读下列代码段,选出该代码段的正确的文件名 ( )class A{ void methodl(){ System.out.println("methodl in class A"); }}public class B{ void method2(){ System.out.println("method2 in class B"); } public static void main(String args[]){ System.out.println("main()in class B"); }}
A.A.java
B.A.class
C.B.class
D.B.java
第5题:
在程序的下画线处应填入的选项是( )。 public class Test {: public static void main(String args[]){ Test t=new Test; Thread tt=new Thread(t); tt.start; } public void run{ for(int i=0;i<5;i++){ System.out.println("i="+i); } } }
A.implements Runnable
B.extends Thread
C.implements Thread
D.extends Runnable
第6题:
下列关于Test类的定义中,正确的是( )。
A.class Test implements Runnable{ public void run{} Dublic void someMethod[]{} }
B.class Test implements Runnable( puIblic void run; }
C.class Test implements Runnable( Dublic void someMethod[]; }
D.class Test implements Runnable( public void someMethod{} }
第7题:
在j2ee中,以下是firevetoablechange方法的正确的原型的是()
第8题:
以下哪些方法在Object类中定义()。
第9题:
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?()
第10题:
class Flow { public static void main(String [] args) { try { System.out.print("before "); doRiskyThing(); System.out.print("after "); } catch (Exception fe) { System.out.print("catch "); } System.out.println("done "); } public static void doRiskyThing() throws Exception { // this code returns unless it throws an Exception } } 可能会产生下面哪两项结果?()
第11题:
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*/} }
第12题:
public void fireVetoableChange(Object oldValue,Object newValue)
public void fireVetoableChange(String propertyName,Object newValue)
public void fireVetoableChange(String propertyName, Object oldValue ,Object newValue)throws PropertyVetoException
public void fireVetoableChange(String propertyName, Object oldValue ,Object newValue)
第13题:
阅读下列函数说明和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("队列已空! ");
}
}
第14题:
把一个对象写到一个流中相对比较简单,具体是通过调用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
第15题:
interface A{
int x = 0;
}
class B{
int x =1;
}
class C extends B implements A {
public void pX(){
System.out.println(x);
}
public static void main(String[] args) {
new C().pX();
}
}
错误。在编译时会发生错误(错误描述不同的JVM 有不同的信息,意思就是未明确的
x 调用,两个x 都匹配(就象在同时import java.util 和java.sql 两个包时直接声明Date 一样)。
对于父类的变量,可以用super.x 来明确,而接口的属性默认隐含为 public static final.所以可
以通过A.x 来明确。
第16题:
对于下面一段代码的描述中,正确的是______。 public class ex36 { public static void run main(String[] args) throws Excepion { method(); } static void method() throws Exception try { System.out.println("test"); } finally { System.out.println ("finally"); } } }
A.代码编译成功,输出“test”和“fmally”
B.代码编译成功,输出“test”
C.代码实现选项A中的功能,之后Java停止程序运行,抛出异常,但是不进行处理
D.代码不能编译
第17题:
下列代码的编译或执行结果是( )。 public class Myval{ public static void main(string args[]){ MyVal m=new MyVal; aMethod; } public void aMethod{ boolean b[]=new Boolean[5]; System.OUt.println(b[0]); } }
A.1
B.null
C.0
D.编译错误
第18题:
阅读以下说明和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("队列已空 ! ");
}
}
第19题:
Object类的finalize()方法是如何声明的()。
第20题:
下列代码正确的是哪项?()
第21题:
现有: class Flow { public static void main(String [] args) try { System. out .print ("before") ; doRiskyThing ( ) ; System.out.print ("after ") ; } catch (Exception fe) { System.out.print ("catch") ; } System. out .println ( " done") ; } public static void doRiskyThing() throws Exception{ // this code returns unless it throws an Exception }} 可能会产生哪两项结果 ?()
第22题:
Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object. class Base { public void print( ) { System.out.println("base"); } } class Extention extends Base { public void print( ) { System.out.println("extension"); // insert line of implementation here } } public class Q294d { public static void main(String args[]) { Extention ext = new Extention( ); ext.print( ); } } Fill in a single line of implementation.()
第23题:
Hello
good-bye
Hellogod-bye
代码不能编译