几个JAVA的问答题 请教大家
8.有如下一段Java程序:importjava.io.*;publicclassQuiz{publicstaticvoidmain(Stringargs[]){intc...
8.有如下一段Java 程序:
import java.io.*;
public class Quiz{
public static void main(String args[]){
int c;
System.out.print("Go ");
try{
System.out.print("in ");
c=System.in.read();
if (c==´0´) {throw new MyException();}
System.out.print("this ");
} catch(IOException e){}
catch(MyException e){
System.out.print("that ");
} finally{
System.out.print("way.\n");
}
}
}
class MyException extends Exception{}
运行该程序后输入字符´0´,请问运行结果为何? __________
(A)Go in this way. (B)Go in this that way.
(C)Go in that (D)Go in that way.
9.接口中可以有的语句为________(从ABCD中多选);一个类可以继承_____ 父类, 实现______接口; 一个接口可继承______ 接口(从EF中单选)。
(A)int x;
(B)int y=0;
(C)public void aa();
(D)public void bb(){System.out.println("hello");}
(E)仅一个
(F)一个或多个
10. 以下程序测试String类的构造函数,试选出其运行结果。
class stringTest{
public static void main(String args[]) {
String s1 = new String();
String s2 = new String("String 2");
char chars[] = { 'a',' ','s','t','r','i','n','g' };
String s3 = new String(chars,2,6);
System.out.println("The String No.1 is " + s1);
System.out.println("The String No.2 is " + s2);
System.out.println("The String No.3 is " + s3);
}
}
(A)The String No.1 is
The String No.2 is String 2
The String No.3 is stri
(B)The String No.1 is
The String No.2 is String 2
The String No.3 is string
(C)The String No.1 is
The String No.2 is String 2
The String No.3 is strin
(D)以上都不对。 展开
import java.io.*;
public class Quiz{
public static void main(String args[]){
int c;
System.out.print("Go ");
try{
System.out.print("in ");
c=System.in.read();
if (c==´0´) {throw new MyException();}
System.out.print("this ");
} catch(IOException e){}
catch(MyException e){
System.out.print("that ");
} finally{
System.out.print("way.\n");
}
}
}
class MyException extends Exception{}
运行该程序后输入字符´0´,请问运行结果为何? __________
(A)Go in this way. (B)Go in this that way.
(C)Go in that (D)Go in that way.
9.接口中可以有的语句为________(从ABCD中多选);一个类可以继承_____ 父类, 实现______接口; 一个接口可继承______ 接口(从EF中单选)。
(A)int x;
(B)int y=0;
(C)public void aa();
(D)public void bb(){System.out.println("hello");}
(E)仅一个
(F)一个或多个
10. 以下程序测试String类的构造函数,试选出其运行结果。
class stringTest{
public static void main(String args[]) {
String s1 = new String();
String s2 = new String("String 2");
char chars[] = { 'a',' ','s','t','r','i','n','g' };
String s3 = new String(chars,2,6);
System.out.println("The String No.1 is " + s1);
System.out.println("The String No.2 is " + s2);
System.out.println("The String No.3 is " + s3);
}
}
(A)The String No.1 is
The String No.2 is String 2
The String No.3 is stri
(B)The String No.1 is
The String No.2 is String 2
The String No.3 is string
(C)The String No.1 is
The String No.2 is String 2
The String No.3 is strin
(D)以上都不对。 展开
5个回答
展开全部
8.D
if (c=='0') {throw new MyException();} 抛出了一个自定义的异常。
所以输出 this 的那个语句不执行。
catch 到 MyException 输出:that
9. BC ,E, F, F.
接口 的 成员变量默认都是 public static final ,必须要初始化,所以A错误。B正确;方法都是抽象方法,所以C正确
一个类只继承一个父类。实现多个接口。
10.B
结果:
The String No.1 is
The String No.2 is String 2
The String No.3 is string
附:API 中的此方法很清楚、
String
public String(char[] value,
int offset,
int count)分配一个新的 String,它包含来自该字符数组参数的一个子数组的字符。offset 参数是子数组第一个字符的索引,count 参数指定子数组的长度。该子数组的内容已被复制;后续对字符数组的修改不会影响新创建的字符串。
参数:
value - 作为字符源的数组。
offset - 初始偏移量。
count - 长度。
抛出:
IndexOutOfBoundsException - 如果 offset 和 count 参数索引字符超出 value 数组的范围。
if (c=='0') {throw new MyException();} 抛出了一个自定义的异常。
所以输出 this 的那个语句不执行。
catch 到 MyException 输出:that
9. BC ,E, F, F.
接口 的 成员变量默认都是 public static final ,必须要初始化,所以A错误。B正确;方法都是抽象方法,所以C正确
一个类只继承一个父类。实现多个接口。
10.B
结果:
The String No.1 is
The String No.2 is String 2
The String No.3 is string
附:API 中的此方法很清楚、
String
public String(char[] value,
int offset,
int count)分配一个新的 String,它包含来自该字符数组参数的一个子数组的字符。offset 参数是子数组第一个字符的索引,count 参数指定子数组的长度。该子数组的内容已被复制;后续对字符数组的修改不会影响新创建的字符串。
参数:
value - 作为字符源的数组。
offset - 初始偏移量。
count - 长度。
抛出:
IndexOutOfBoundsException - 如果 offset 和 count 参数索引字符超出 value 数组的范围。
展开全部
8.A
9.CE E E F
10.D
9.CE E E F
10.D
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
(1).D
(2).ABC E F F
(3).B
(2).ABC E F F
(3).B
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
8.D(在Try块中抛出异常后在抛异常后面得代码是不执行的)
9.BC E F E(在接口中定义常量就要赋值,方法没有方法体,类继承父类和接口继承接口是一样的道理 只能单一继承 ,接口实现的话一个类可以实现一个或者任意多个借口)
10.C(这是一个传参的问题 可以把数组作为一个参数传递)
9.BC E F E(在接口中定义常量就要赋值,方法没有方法体,类继承父类和接口继承接口是一样的道理 只能单一继承 ,接口实现的话一个类可以实现一个或者任意多个借口)
10.C(这是一个传参的问题 可以把数组作为一个参数传递)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼长是正确的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询