java的几道基础选择题
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/21 01:15:14
java的几道基础选择题
10. Which of the following statements is correct about Java package?
A. If there is no packagestatement used, the current class will not be in any package.
B. Package is a way to manage source code, eachpackage contains several “.java” files.
C. Using one “import”statement can include the classes from one or more packages.
D. A package cancontain sub-packages.
选D
11. Given:
1. public class Target {
2. private int i = 0;
3. public int addOne() {
4. return ++i;
5. }
6. }
And:
1. public class Client {
2. public static void main(String[] args) {
3. System.out.println(new Target().addOne());
4. }
5. }
Which change can you make to Targetwithout affecting Client?
A. Line 4 of class Target can bechanged to returni++;
B. Line 2 of class Target can bechanged to privateint i = 1;
C. Line 3 of class Target can bechanged to privateint addOne() {
D. Line 2 of class Target can be changed to private Integer i = 0;
选D
17.Method m() is defined as below in a parent class, which method in thesub-classes overrides the method m()?
protected double m() { return 1.23;}
A. protect int m() { return 1; }
B. public double m() {return 1.23; }
C. protected double m(double d) { return 1.23; }
D. private double m() { return 1.23; }
选B
为什么,不懂,能否举个例子?
10. Which of the following statements is correct about Java package?
A. If there is no packagestatement used, the current class will not be in any package.
B. Package is a way to manage source code, eachpackage contains several “.java” files.
C. Using one “import”statement can include the classes from one or more packages.
D. A package cancontain sub-packages.
选D
11. Given:
1. public class Target {
2. private int i = 0;
3. public int addOne() {
4. return ++i;
5. }
6. }
And:
1. public class Client {
2. public static void main(String[] args) {
3. System.out.println(new Target().addOne());
4. }
5. }
Which change can you make to Targetwithout affecting Client?
A. Line 4 of class Target can bechanged to returni++;
B. Line 2 of class Target can bechanged to privateint i = 1;
C. Line 3 of class Target can bechanged to privateint addOne() {
D. Line 2 of class Target can be changed to private Integer i = 0;
选D
17.Method m() is defined as below in a parent class, which method in thesub-classes overrides the method m()?
protected double m() { return 1.23;}
A. protect int m() { return 1; }
B. public double m() {return 1.23; }
C. protected double m(double d) { return 1.23; }
D. private double m() { return 1.23; }
选B
为什么,不懂,能否举个例子?
第十题:
A 不对,如果没用声明package则处于一个默认包下,所有的未声明package的类都处于此包下.
B不对,package是用来管理类文件的,也就是.class文件.
C不对,依据import只能引用一个包下的类.
D正确,包下可以含有子包.
----------------------------------------------
第十一题:
A不对,以为这样改代码后,client将输出0.
B不对,client输出2.
C不对,因为client将不能访问target的addone()函数.
D对,因为java5.0版本后,支持自动装箱、拆箱操作,基本类型的包装类支持基本运算.
----------------------------------------------------
第十七题:
只有B对,因为要想覆盖父类中的函数,子类中声明的函数必须满足下面几点:
1、形参列表必须一致;
2、函数名必须一致;
3、返回值类型必须一致,有个特例,子类中的返回值类型可以是父类中返回值类型的子类;
4、public、protected、private修饰符可以不一致,但是必须更加严格;
5、抛出的异常可以不一致,但必须保证抛出的异常是父类中函数抛出异常的子集;
A 不对,如果没用声明package则处于一个默认包下,所有的未声明package的类都处于此包下.
B不对,package是用来管理类文件的,也就是.class文件.
C不对,依据import只能引用一个包下的类.
D正确,包下可以含有子包.
----------------------------------------------
第十一题:
A不对,以为这样改代码后,client将输出0.
B不对,client输出2.
C不对,因为client将不能访问target的addone()函数.
D对,因为java5.0版本后,支持自动装箱、拆箱操作,基本类型的包装类支持基本运算.
----------------------------------------------------
第十七题:
只有B对,因为要想覆盖父类中的函数,子类中声明的函数必须满足下面几点:
1、形参列表必须一致;
2、函数名必须一致;
3、返回值类型必须一致,有个特例,子类中的返回值类型可以是父类中返回值类型的子类;
4、public、protected、private修饰符可以不一致,但是必须更加严格;
5、抛出的异常可以不一致,但必须保证抛出的异常是父类中函数抛出异常的子集;