题目内容

考虑如下代码:
class Tree{}
class Pine extends Tree{}
class Oak extends Tree{}
public class Forest {
public static void main(String[] args ) {
Tree tree = new Pine();
if(tree instanceof Pine )
System.out.println("Pine" );
if(tree instanceof Tree )
System.out.println("Tree" );
if(tree instanceof Oak )
System.out.println("Oak" );
else
System.out.println("Oops" );
}
}
则输出结果中有哪些?

A. Pine B.Tree C.Forest D.Oops E.无输出

查看答案
更多问题

编译和运行以下程序结果为:
1: public class Q21 {
2: int maxElements;
3: void Q21() {
4: maxElements = 100;
5: System.out.println(maxElements);
6: }
7: Q21(int i) {
8: maxElements = i;
9: System.out.println(maxElements);
10: }
11: public static void main(String[] args) {
12: Q21 a = new Q21();
13: Q21 b = new Q21(999);
14: }
15: }

A. 输出100 和 999.
B. 输出999 和 100.
C. 第2行出现编译错误,变量 maxElements未初始化.
D. 12行出现编译错误.

下列说法错误的一项是?

A. getDocumentBase()用于获取包含Applet的HTML文件的URL
B. getCodeBase()用于获取Applet主类的URL
C. getParameter(String name)用于获取标记中的参数值
D. 若指定参数在HTML中没有说明,则Applet将停止运行。

下列程序运行的结果为:
public class Example{
String str=new String("good");
char[] ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+" and ");
Sytem.out.print(ex.ch);
}
public void change(String str,char ch[]){
str="test ok";
ch[0]='g';
}
}

A. good and abc
B. good and gbc
C. test ok and abc
D. test ok and gbc

以下程序调试结果为:class Base{Base(){int i = 100;System.out.print (i);}}public class Pri extends Base{static int i = 200;public static void main(String argv[]){Pri p = new Pri();System.out.print(i);}}

A. 编译错误
B. 200
C. 100200
D. 100

答案查题题库