该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Java程序设计试卷样品
第一部分:对于下列1~33问题,选择正确的回答或填空(每题2分,总66分)
下列哪个修饰符是错误的?
A.private
B.public
C.protected
D.friendly
如果一个类的成员变量只能被同一个包所访问,使用下列哪个修饰符?
A.private
B.public
C.protected
D.no modifier
下列哪个陈述是正确的?
A.在Java 中,单一继承是允许的,它使得代码更可靠。
B.一个子类继承父类的所有方法(包括构造方法)。
C.一个类仅能实现一个所需的接口。
D.当一个类实现一个接口时,它能定义所需的与接口一样多的方法。
在Test.java 源文件中,哪个是正确的类定义?
A.public class test {
public int x = 0;
public int test(int x) {
this.x = x;
}
}
B.public class Test{
public int x=0;
public Test(int x) {
this.x = x;
}
}
C.public class Test extends T1, T2 {
public int x = 0;
public void Test (int x) {
this.x = x;
}
}
D.protected class Test extends T2{
public int x=0;
public Test(int x){
this.x=x;
}
}
给出下列代码
public class Test{
public static void main(String args[]){
String str=new String("World");
char ch[]={'H','e','l','l','o'};
change(str,ch);
System.out.println(str + "and" + ch);
}
public static void change(String str, char ch[]){
str="Changed"; ch[0]='C';
}
}
程序运行的结果是下列哪个?
A.World and Hello
B.World and Cello
C.Changed and Hello
D.Changed and Cello
分析下列两条语句:
int i = f;
float f = 3.2;
选择不正确的回答
A.这个代码不能编译。
B.这个代码能编译并且变量i 设置为3。
C.如果第一行改为int i = (byte)f;,则第二行能编译。
D.如果第二行改为float f = 3.2F;,则第二行能编译。
下列语句执行后,temp 的最终植是什么?
long temp = (int)3.9;
temp %= 3;
结果是:
分析下列两个类:
final class First {
本文详细解读了Java中修饰符、访问权限、继承与实现的规则,包括私有、公共、受保护和无修饰符的区别,以及类的单一继承和接口实现的特性。通过实例演示,讨论了类定义的正确形式和代码编译与运行结果。还涵盖了数据类型转换和运算符的适用性。
1459

被折叠的 条评论
为什么被折叠?



