当前位置:首页 > JAVA语言程序设计期末考试试题和答案
.
}
public void print(){ System.out.println(one); } }
public class Child extends Parent { public Child(String a, String b){ super(a,b); }
public void print(){
System.out.println(one + \ }
public static void main(String args[]){ Parent p = new Parent(\ Parent t = new Child(\ p.print(); t.print(); } }
下面的哪些情况或输出的结果正确? [E] A. 编译时出错 B. south east
C. south to north east to west D. south to north east E. south east to west
39. 类Teacher和Student都是类Person的子类 Person p; Teacher t;
.
.
Student s;
若p,t和s都是非空值
if(t instanceof Person) { s = (Student)t; }
这个语句导致的结果是什么? [C] // 默认new时声明的都是本类; A. 将构造一个Student对象 B. 表达式合法 C. 编译时非法
D. 编译时合法而在运行时可能非法
40. 给出下面的代码 String s= \String t = \
char c[] = {'h','e','l','l','o'}; 下列选项里,哪些返回true? [ACD] A. s.equals(t); B. t.equals(c); C. s==t;
D. t.equals(new String(\E. t==c;
一、单选题(本大题15小题,每小题2分,共30分) 1.下列语句执行后,变量a、c的值分别是( )。 int x=182; int a,c; c=x/100; a=x;
A) 1,2 B) 2,1 C) 1.82, 2 【答案】B
2.下面哪个表达式可用得到x和y的最大值( )?
A) x>y?y:x B) x
D) 100,82 D) x==y?y:x;
.
【答案】B
3.以下是应用程序中定义的静态方法printBinary,若在其main方法中有方法调用语句printBinary(2),则输
出的结果是 ( )。
static void printBinary(int i) {
System.out.print(i + \的2进制数表示为:\\t\ for(int j = 31; j >=0; j--) if(((1 << j) & i) != 0) System.out.print(\ else
System.out.print(\ System.out.println();//换行 }
A) 00000000000000000000000000000001 B) 00000000000000000000000000000010 C) 00000000000000000000000000001111 D) 00000000000000000000000000000000 【答案】B
4. 应用程序的main方法中有以下语句,则输出的结果是 ( )。 String s1=\
double x=Double.parseDouble(s1); int y=Integer.parseInt(s2); System.out.println(x+y);
A) 12.5 B) 120.5 C) 12 D) “12.5” 【答案】A
5. 应用程序的main方法中有以下语句,则输出的结果是 ( )。 double x=1234.1234567;
DecimalFormat form1 = new DecimalFormat(\ System.out.println(\A) PI=1234.1 B) PI=1234 C)
.
PI=1234.1235 D) PI=1234.0
.
【答案】A
6.下列程序段执行后的结果是( )。 String s=new String(\for(int i=0;i aceg B) ACEG C) abcdefg 【答案】A 7. 应用程序的main方法中有以下语句,则输出的结果是 ( )int[] x={122,33,55,678,-987}; int max=x[0]; for(int i=1;i System.out.println(max); A) 678 B) 122 C) -987 【答案】A 8.下列语句序列执行后,k 的值是( )。 int x=2, y=5, k=0; switch( x%y ) { case 0: k=x+y; break; case 1: k=x-y; break; case 2: k=x*y; break; default: k=x/y; break; } System.out.println(k); A) 2 B) 5 C) 10 【答案】C 9. 下面的程序输出的结果是( ) . D) abcd 。 D) 33 D) 0
共分享92篇相关文档