设有如下代码:
class Base{}
public class MyCast extends Base{
static boolean b1=false;
static int i = -1;
static double d = 10.1;
public static void main(String argv[]){
MyCast m = new MyCast();
Base b = new Base();
//Here
}
}
则在 //Here处插入哪个代码将不出现编译和运行错误。
A.b=m;
B.m=b;
C.d =i;
D.b1 =i;
第1题
考虑如下代码:
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.无输出
第2题
设有类定义如下:
class InOut{
String s= new String("Between");
public void amethod(final int iArgs){
int iam;
class Bicycle{
public void sayHello(){
//Here
}
}
}
public void another(){
int iOther;
}
}
以下哪些语句可以安排在//Here处 ?
A. System.out.println(s);
B.System.out.println(iOther);
C. System.out.println(iam);
D. System.out.println(iArgs);
第3题
设有如下代码:
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef bj = new ObRef();
Base b = new Base();
Object obj1 = new Object();
IFace obj2 = new CFace();
//Here
}
}
则在 //Here处插入哪个代码将不出现编译和运行错误。
A.obj1=obj2;
B.b=obj;
C.obj=b;
D.obj1=b;
第4题
A.myInt = myByte;
B.myInt = myLong;
C.myByte = 3;
D.myInt = myChar;
E.myFloat = myDouble;
F.myFloat = 3;
G.myDouble = 3.0;
第5题
以下的程序的调试结果为?
public class As{
int i = 10;
int j;
char z= 1;
boolean b;
public static void main(String argv[]){
As a = new As();
A.amethod();
}
public void amethod(){
System.out.println(j);
System.out.println(b);
}
}
A.输出0 和false
B. 输出0 和true
C. 编译错误,b 未初始化
D. 编译错误, z 必须赋字符值
第6题
A. Point.x Point.y
B.无解
C. x1 y1
D.this.x this.y
第7题
A.编译指示带有final 方法的类自己必须定义为final
B.编译指示不能继承含有final 方法的类
C.运行错误,原因是Base类没有定义为final类
D.运行输出 amethod
第9题
下列程序运行的结果为:
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
第10题
A. 输出结果为:0
B. 无输出
C. 编译错误
D. 输出null
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!