翰子昂阶段性测试_S1阶段—JAVA方向理论测试试题
public class Test{
public static void main(String args []){ int a; int b=0; int max; max = (b-1)>a?b:a; System.out.println(“The max is”+max); } }
a) 编译,运行后没有输出
b) 编译,运行后输出:The max is 0 c) 能通过编译,但运行时产生错误 d) 不能通过编译
24. 给出以下代码,请问该程序的运行结果是什么?( d )。(选择一项) public class Example{
public static void main(String args[]){ int x = 1, y = 6;
while(y--){ while 与 if 语句括号里面都是boolean类型的或者返回类型是boolean x++; }
System.out.println(“x = ”+x+” y = ”+y); } }
a) x = 6 y = 0 b) x = 7 y = 0 c) x = 6 y = -1 d) 编译错误
25. 以下哪些不是java的基本数据类型( b )。(选择一项) a) short b) Boolean c) float d) double
26. 下面哪些不是Java的常用命令( bd )。(选择两项) a) javac b) ftp c) java d) cd
27. 给出以下代码,请问该程序的运行结果是什么?( b )。(选择一项) public class Example{
public static void main(String args[]){
int i = 0; while (true) { if(i==4) {
break;
第6页 共10页
翰子昂阶段性测试_S1阶段—JAVA方向理论测试试题
} ++i;
}
System.out.println(\
}
}
a) i = 0 b) i = 4 c) i = 3
d) 编译错误
28. 以下哪些是有关完全封装的正确描述( ac )。(选择两项) a) 所有变量都是私有的
b) 所有方法都是私有的 set 与get 方法 c) 只有通过提供的方法才能访问类属性 d) 类设计的改变对实现的影响最小
29. 以下哪些有关接口的描述是正确的?( c )。(选择一项)
a) 在接口中定义的方法默认为private方法 默认方法为default b) 在接口中定义的方法默认为public、static、final方法 c) 一个接口可以继承多个接口 d) 关键字implements代表继承关系
1. 接口的所有分方法都是抽象方法,所有的属性都是常量 接口用来表示纯抽象类的概念没有具体的方法和属性
2. 可以声明变量,不能实例化(不能实例化这个接口 如:new 接口) 3. 接口变量可以应用具体实现类的应用
4. 接口只能被实现,一个具体类实现这个借口就要实现这个这个类的所有方法 5. 接口之间可以继承,
6. 一个具体类可以实现多个内容
7. 接口中的属性默认为常量,public 、static 、final 8. 接口中的方法全是 public abstract
9.实现一个接口使用关键字implements,接口与实现类之间是父子类关系
30. 请问以下哪些是类Example的有效构造器( b )。(选择一项) a) public void example(){} 类的单词首字母必须是大写 b) public Example(){} 有时候没有public 也是对的 c) static Example(){}
d) public static Example(){}
31. 给出以下代码,请问该程序的运行结果是( c )。(选择一项)
public class Example{
public static void main(String [] args){ int i = 0 , j = 2;
第7页 共10页
翰子昂阶段性测试_S1阶段—JAVA方向理论测试试题
do{ i = ++i; j--; }while(j>0);
System.out.println(i);
}
}
a) 打印输出0 b) 打印输出1 c) 打印输出2 d) 代码编译失败
32. 给出以下代码,请问该程序的运行结果是什么?( d )。(选择一项) class Example{
public static void main(String args[]){ int i = 1, j = 10; do{
if(i++>--j)continue; }while(i<5);
System.out.println(“i = ” + i + “ j = “ + j); } }
a) 打印输出 i = 6 j = 5 b) 打印输出 i = 5 j = 5 c) 打印输出 i = 6 j = 4 d) 打印输出 i = 5 j = 6
优先级:算数运算符>赋值运算符,关系运算符,夺目运算符(? :)。 1. 数学运算符:+ - * / % (算数运算符)
2. 关系运算符:&&(短路与) ||(短路或) & | !(逻辑运算符) 3. 自增运算符:++ --
4. 多目运算符: ?: 例如:a>b?a:b 5. 赋值运算符: =
33. 给定某java程序的main方法,如下:( b )。(选择一项)
public static void main(String[ ] args) {
int i = 0;
System.out.println(++i) ; }
a) 0 b) 1
c) 编译错误 d) 运行时出现异常
34. 给出以下代码,请问在程序的第3行处插入哪条语句,该程序会出现编译错误((选择一项) 1.public class Example{
第8页 共10页
d )。 翰子昂阶段性测试_S1阶段—JAVA方向理论测试试题
2. public static void main(String[] args){ 3. //添加代码处
4. switch(x){ 可以放 枚举类型byte、int、short、char 但是不能放long 5. default:
6. System.out.println(“That is OK!”); 7. } 8. } 9.}
a) int x = 6; b) short x = 3; c) char x = ?y?; d) long x = 354;
35. 以下哪些修饰符不能用于类成员?( c )。(选择一项) a) public b) private c) friendly d) protected
36. 给出以下的代码,请问哪些选项中的代码可以添加到第4行处?( a d )。(选择两项) 1.public class Test{
2. public float aMethod(float a, float b){ 3. }
4.//添加代码处 5.}
a) public int aMethod(int a, int b){}
b) public float aMthod(float a, float b){}不能定义两个完全相同的方法 c) public float aMthod(float c, float d){} d) private float aMthod(int a,int b,int c){} 重写发生在父子类之间 这一题目是重载
37. 以下哪些有关String类的描述是错误的?( d )。(选择一项) a) 该类是一个final类 b) 该类是一个public类 c) 该类可以序列化
d) toUpper()方法是String类中的
38. 给定Java代码,String s = new String(“xyz”);以下哪些语句正确的是( c )。(选择一项) a) s = 2 * s; b) int i = s[0]; c) s = s + s; d) s = s >> 2;
第9页 共10页
翰子昂阶段性测试_S1阶段—JAVA方向理论测试试题
39. 给出以下代码,请问该程序的运行结果是什么?( b )。(选择一项) public class Example{
public static void main(String[] args){
String s = “abcdefg”; System.out.println(s.charAt(4)); } }
a) 打印输出d b) 打印输出e c) 无内容输出 d) 代码编译失败
40. 给出以下代码,请问该程序的运行结果是什么?( public class Example{
public static void main(String args[]){
String s1 = “abc”; String s2 = “def”; String s3 = new String(s2); s2 = s1; System.out.println(s3); } }
a) 打印输出def b) 打印输出abc c) 打印输出null
d) 在执行s2 = s1;语句时抛出异常
第10页 共10页
a )。(选择一项)