1 、给出下面的代码段 : public class Base{
int w, x, y ,z;
public Base(int a,int b) {
x=a;
y=b;
}
public Base(int a, int b, int c, int d) {
// assignmentx=a, y=b
w=d;
z=c;
}
} 在代码说明 // assignment x=a, y=b 处写入如下哪个代码是正确的? D
A 、 Base(a,b);
B 、 x=a, y=b;
C 、 this(a),this(b);
D 、 this(a,b);
2 、如下哪个不是 Java 中正确的整数表示 ? D
A 、 22
B 、 0x22 ——8进制
C 、 022 ——16进制
D 、 22H
3 、指出下列程序运行的结果(D) ---- 应该是B
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〃);
System.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
4 、下面哪条语句定义了 5 个元素的数组 A )
A、int [] a={22,23,24,25,12};
B、int a []=new int(5); ——————定义数组 int a [] = new int【5】
C、int [5] array;
D、int [] arr;
5 、对于 catch 子句的排列,下列哪种是正确的( B ) ————考点是 :catch捕获异常后会直接finally,不会向下继续catch,所以子先父后
A.父类在先,子类在后
B.子类在先,父类在后
C.有继承关系的异常不能在同一个 try 程序段内
D.如何排列都可以
6 、已知如下代码:
1: class Example{
2: String str;
3: public Example(){
4: str= "example";
5: }
6: public Example(String s){
7: str=s;
8: }
9:}
10: class Demo extends Example{
11: }
12: public class Test{
13:public void f () { 14:Example ex = new Example("Good");
15:Demo d = new Demo("Good");
16:} }
哪句语句会导致错误? E —— 构造方法不继承
A 、 line 3
B 、 line 6
C 、 line 10
D 、 line 14
E 、 line 15
7 、给出一段程序,试判断哪个是正确的结果( B
public class rtExcept{
public static void throwit(){
System.out.print(“throwit”);
throw new RuntimeException();
}
public static void main(String [] aa){
try{
System.out.print(“hello “);
throwit();
}
catch(Exception re){
System.out.print(“caught ”);
}
finally{
System.out.print(“finally ”);
}
System.out.print(“after ”);
} }
A、hello throwit caught B、hello throwit caught finally after
C、hello throwit RuntimeException after D、hello throwit caught finally after RuntimeException )
8 、public class Foo{
public static void main(String sgf[]){
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
operate(a,b);
System.out.println(a+","+b);
}
static void operate(StringBuffer x,StringBuffer y){
x.append(y); y=x; }
} What is the result?
A.The code compiles and prints “A.B”.
B.The code compiles and prints “A.A”.
C.The code compiles and prints “B.B”.
D.The code compiles and prints “AB.B”.
E.The code compiles and prints “AB.AB”. 答案是 D
java 中都是按值传递的,所以 a,b 还是指向原来的地址空间,经过 operate 操作后,x 更改 了该地址空间的值,而 y 没有.
public class Foo{ public static void main(String sgf[]){ StringBuffer a = new StringBuffer("A"); StringBuffer b = new
StringBuffer("B"); operate(a,b); //方法调用完以后,a 对象的内容为:AB,b 对象的内容为:B System.out.println(a+","+b); }
static void operate(StringBuffer x,StringBuffer y){ //对象传递进来以后又分别复制了一个 x 和 y 对象 x'和 y', x'和 x 指
向同一个对象。y'和 y 指向同一个对象。 x.append(y); //所以执行此步操作以后,main 中的 x 对象的内容也变化了。 //因为本来
就是指向同一个对象吗! y=x; //执行此步操作以后,main 中的 y 对象的内容没变! //因为此 y 费彼 y 也! } }
9.class ValHold{ public int i = 10; }
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod
public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another
}
1) 10,0,30
2) 20,0,30
3) 20,99,30
4) 10,0,20 答案是 4)
首先必须明白一点 参数传递到方法内的时候实际上是复制了一份 而且 java 并不直接处理对象,而是通过对象参考来处理的。
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod
public void another(ValHold v, int i){ //参数 v,i 传进来后进行复制,并且两个 v 都是指向同一个对象
i=0;
v.i = 20; //这里就导致所指向的对象的 i 值变化
ValHold vh = new ValHold();
v = vh; //这里改变了 v 的对象参考,指向新的一个 ValHold 对象
System.out.println(v.i+ " "+i);
}//End of another
}
10.Given the following code 4)
class Base {}
class Agg extends Base{
public String getFields(){
String name = "Agg"; return name;
}
}
public class Avf{
public static void main(String argv[]){
Base a = new Agg();
//Here
}
} What code placed after the comment //Here will result in calling the getFields method resulting in the output of the
string "Agg"?
1)System.out.println(a.getFields());
2)System.out.println(a.name);
3)System.out.println((Base) a.getFields());
4)System.out.println( ((Agg)a).getFields());
answer 1:a's reference type is Base ,not Agg,so method getFields not found ... Base a=new Agg(); change>>>> Agg a =new Agg(); compile correct..
answer 2:variable name not found..
answer 3:the reason is the same as answer1
answer 4:correct
11.请看以下例子:
1).
public class Test{
public static void main(String argv[]){
Test t = new Test();
t.amothed();
}
void amothed(){
byte[] a;
System.out.println(a[0]);
}
} 编译时报错:变量 a 可能未被初始化。
2).
public class Test{
public static void main(String argv[]){
Test t = new Test();
t.amothed();
}
void amothed(){
byte[] a = new byte[5];
System.out.println(a[0]);
}
} 编译通过,输出 0。 数组是会自动初始化的……这肯定没错…… 但你必须先把它实例化……
int[] a;//定义一个整型数组,但尚未实例化……
a = new int[3];//实例化 a,同时 a 的所有元素被初始化为 0……
System.out.println(a[0]);
System.out.println(a[1]);
System.out.println(a[2]);
13.For the following code:
class Super
int index = 5;
public void printVal() { System.out.println( "Super" ); }
class Sub extends Super
int index = 2;
public void printVal() { System.out.println( "Sub" ); }
public class Runner
public static void main( String argv[] ) {
Super sup = new Sub();
System.out.print( sup.index + "," );
sup.printVal();
} What will be printed to standard output?
The code compiles and "5, Sub" is printed to standard output. .
成员变量是编译时绑定,
Super sup = new Sub(); //这里声明 sup 为 Super, 所以在编译时, 就确定了 sup.index=5
System.out.print( sup.index + "," );//打印出 5 成员函数则是动态绑定,
sup.printVal(); //尽管 sup 被声明为 super,但是实际上是 new Sub(),所以在运行时, sup实际上指向的一个 Sub 对象。由于是动
态绑定,所以这里执行的是 Sub 的方法。
14.class A { ——
这个是类的初始化,并不是实例的初始化,实例的初始化打印3次5 static int si=5;
static { System.out.println(si);}
A(){ si++;}
public static void main(String args[]) {
for (int i=0;i<3;i++) new A();
}
}
参考答案:print out "5" once 当类加载的时候首先是初始化 static 类变量和执行 static 类方法, 只有这一次机会。 此时 也许
还没有一个类实例。 以后所有对象都共享 static 变量。 static 类变量的修改会影响 对 到 所有的类实例。
15.class Z {
public static void main(String args[]) {
System.out.println("AAA"+new Z());
}
public String toString() {
System.out.println("###");
return "Z";
}
} 参考答案:"###" followed by "AAAZ" 要 打 印 "AAA"+new Z() , 就 要 先 把 他 翻 译 成 字 符 串 , 要 想 翻 译 成 字
符 串 就 要 先 执 行 z.toString(),所以先遇到了打印“###” ,于是打印了出来,然后 z.toString()执行完毕, 然后开始执行
打印"AAA"+"z",顺序是这样的。
16.What is the output of the following program
public class Test {
private int i = giveMeJ();
private int j = 10;
private int giveMeJ() { return j; }
public static void main(String args[]) {
System.out.println((new Test()).i);
}
}
Select one correct answer
a. Compiler error complaining about access restriction of private variables of AQuestion.
b. Compiler error complaining about forward referencing.
c. No Compilation error - The output is 0;
d. No Compilation error - The output is 10;
答案是: c。生成 test 类,首先为 i,j 分配空间并初始化为 0,然后执行 i=giveMeJ(),这时 j 还是 0,所以 i 的结果为 0;然后
执行 j=10。所以最后输出为 0。
这道题与13题有着异曲同工的意义,在初始化时是类的初始化,这时i,j都有了,但是指向的值均为0
17.What will happen if you compile/run the folowing lines of code?
1: Vector a = new Vector();
2:
3: a.addElement(10);
4:
5: System.out.println(a.elementAt(0));
A) Prints 10
B) Prints 11
C) Compilation error at line 3
D) Prints some garbage.
答案是 C。Vetor 接受的是一个对象,不是一个 primitive type ,接受type时,用add
分享到:
相关推荐
在给定的文件信息中,涉及到了五个不同的编程题目和知识点...以上是对【2022年蓝桥杯】蓝桥杯第一次海选考试题的知识点详细说明。通过这些题目的练习,学生不仅能够加深对编程语言的理解,还能提高解决实际问题的能力。
20. 更改Exchange配置需在控制面板中选择“电子邮件”选项。 此外,存储容量的基本单位Byte表示8个二进制位,一个ASCII码字符通常用1个Byte表示,计算机键盘是输入设备,能直接执行的程序是机器语言程序,操作系统...
1. **试题库管理**:系统需要一个庞大的、包含各种类型(如选择题、填空题、简答题等)的试题库,试题应涵盖课程的所有知识点,且具有一定的难度梯度和随机性。 2. **试卷生成**:根据预设的规则(如题目数量、难度...
《考试抽题存题系统——高效管理与智能化抽题的桌面解决方案》 考试抽题存题系统是一款专为教育行业设计的桌面应用软件,旨在帮助教师和考试组织者更便捷地管理和组织考试题目,实现题库的高效利用。通过这款系统,...
《单项选择题标准化考试系统——基于C语言与Visual Studio的实现》 在计算机科学教育领域,编程课程的实践环节往往需要学生完成各种项目,以巩固理论知识并提升编程能力。"单项选择题标准化考试系统"就是一个这样的...
#### 一、单项选择题解析 **23. 多任务操作系统的特点** - **选项分析:** - **I.具有并发和并行的特点**:正确。多任务操作系统允许多个任务同时进行,即并发执行;在多核或多处理器系统中,这些任务可以在不同...
- **考试结果表(ExamResults)**:存储每次考试的结果,如总分、通过/未通过状态等。 2. **用户管理**: - **管理员登录模块**:使用MySQL的存储过程或触发器实现用户验证,确保只有授权的管理员能登录并进行...
【ASP.NET 源码——面向大学的在线网络考试系统】是一个基于ASP.NET技术开发的教育信息化解决方案,专为大学设计,旨在实现高效、便捷的网络考试功能。这个系统允许教师创建、管理试题库,组织在线考试,同时学生...
- 选择题中的选项CD正确,软件工程的三要素包括方法、工具和过程,其中过程是指软件开发过程的组织和管理方式,而非模型。 **3. 包含风险分析的软件工程模型:** - 选项A(螺旋模型)正确,因为螺旋模型的特点是在...
这份资料——“高考英语听说考试真题B录音原文与参考答案.pdf”——提供了2021年广东省高考英语听说考试Part B三问局部的真题和答案,帮助考生提升听力理解能力和口语表达技巧。 Part B三问局部通常涉及日常生活、...
1. 题库管理:随机抽题考试系统的核心是题库,管理员可以方便地添加、修改和删除题目,包括选择题、填空题、判断题等多种题型。ASP技术使得题库的数据存储和管理变得简单,通过数据库如Access或SQL Server进行后台...
在程序设计领域,构建一个考试系统涉及到众多技术层面,其中数据存储是至关重要的一环。本节将深入探讨“考试系统”的数据存储问题,包括试题、答案、选项以及用户信息等关键数据的管理。 首先,考试系统的功能主要...
方案一的投资额为40000万元,建成后可通行20年,每年需维护费1000万元,每10年需进行一次大修,每次大修费用为3000万元,运营20年后报废时没有残值。 方案二的投资额为120000万元,建成后可通行60年,每年需维护费...
模拟考试部分,ASP可以构建一个交互式的测试界面,用户选择开始考试后,服务器将从题库中按设定规则抽取题目。考试时间限制、自动提交、答案检查等功能可以通过JavaScript和服务器端的ASP配合完成。用户完成答题后,...
#### 一、选择题 ##### 题目1:说“我喜欢Apple” - **题目描述**:本题考查学生对于Scratch基本模块的理解与应用,即如何让角色说出指定的文字。 - **知识点解析**:在Scratch中,可以通过拖拽“说”模块到脚本...
为了实现随机抽取试题的功能,开发者需要设计算法从题库中选择一定数量的试题,确保每次考试的试题组合不重复。这涉及数据库查询优化和算法设计。 **交互式答题界面** ASP可以创建HTML表单,用于显示试题和收集用户...
15. 关键词分组策略:将相关性强的关键词归为一组,例如汽车相关词可分在一组,商务轿车、大众迈腾等作为子组。 16. 转化漏斗理解:访问量和咨询量反映企业网站阶段,订单量反映线下销售阶段,展现量和点击量反映...
1. 在选择题中,第一题强调了观察作为科学探究方法的重要性,指出观察需要明确目的,全面、仔细,并做记录,但并不一定每次观察都需要长时间。 2. 第二题考察了生物的定义,正确答案表明只有活的、具有生命特征的...
【农电安全生产知识调考试题集——防交通事故类】主要关注的是电力行业的交通安全问题,旨在提升员工对于防止交通事故的认识和遵守交通规则的意识。以下是该文档中涉及的主要知识点: 1. **交通安全责任制**:强调...
在当前紧张备考的氛围中,高三学子们正面临着人生中的...在备考过程中,高三学生应该抓住每次模拟考试的机会,认真分析自己的答题情况,积极弥补知识漏洞,这样才能在高考中展现出最佳状态,迎接人生的又一次重要飞跃。