JAVA基础 第3章练习_类与对象_2012
- 格式:doc
- 大小:62.50 KB
- 文档页数:6
第3章类与对象
一.选择题
1.下列不属于面向对象编程的特性是()。
A.封装性 B. 继承性 C. 多态性 D. 编译执行性
2.下列类的声明中不合法的是()。
A. class People{…}
B. class 植物{…}
C. Class A{…}
D. public class 共有类{…}
3.下列方法的声明中不合法的是()。
A. float area(){…}
B. void area(){…}
C. double area(d){…}
D. int area(int r){…}
4. 下列构造方法的调用中正确的是()。
A. 按照一般的方法调用
B. 由用户直接调用
C. 只能通过new自动调用
D. 被系统调用
5.下列程序运行的结果是()。
class Book{
int width;
int length;
}
public class A{
static void f(Book p){
p.width=20;
p.length=40;
}
public static void main(String args[]){
Book b=new Book();
b.width=10;
b.length=20;
f(b);
System.out.print(" "+b.width);
System.out.print(" "+b.length);
}
}
A. 20 40
B. 10 40
C. 10 20
D.以上都不对
6.下列程序运行的结果是()。
public class A{
static void f(int y){
y=y+10;
}
public static void main(String args[]){
double x=10;
f(x);
System.out.println(x);
}
}
A. 10
B. 20
C. 10.0
D.程序编译错误
7.下列程序运行的结果是()。
public class A{
int z=20;
static void f(int y){
y=z;
System.out.println(y);
}
public static void main(String args[]){
f(10);
}
}
A. 10
B. 20
C. 程序编译错误
D. 以上都不对
8. 以下代码的输出结果为()。
public class Pass{
static int j=20;
public static void main(String args[]){
int i=10;
Pass p = new Pass();
p.amethod(i);
System.out.println(i+" and "+j);
}
public void amethod(int x){
x=x*2;
j=j*2;
}
}
A.错误: 方法参数与变量不匹配 B. 20 and 40
C. 10 and 40
D. 10 and 20
9. 编译和运行程序会出现什么样的结果()。
public class Ref{
public static void main(String args[]){
Ref r = new Ref();
r.amethod(r);
}
2
第3章练习类与对象大外软件学院
public void amethod(Ref r){
int i=99;
multi(r);
System.out.println(i);
}
public void multi(Ref r){
r.i = r.i * 2;
}
}
A.编译出错 B. 输出:99
C. 输出:198
D. 运行出错
10. 关于以下程序代码的说明正确的是()。
1.class HasStatic{
2. static int x=100; int y=0;
3. public static void main(String args[]){
4. HasStatic hs1=new HasStatic();
5. hs1.x++;
6. HasStatic hs2=new HasStatic();
7. hs2.x++;
8. hs1=new HasStatic();
9. hs1.x++;
10. HasStatic.x- -;
11. System.out.println("x="+x);
12. }
13.}
A.5行不能通过编译,因为引用了私有静态变量
B.10行不能通过编译,因为x是私有静态变量
C.程序通过编译,输出结果为:x=103
D.程序通过编译,输出结果为:x=102
11. 有如下代码:
public class Test {
void printValue(int m){
do {
System.out.println("The value is"+m);
}while( --m > 10 );
}
public static void main(String arg[]) {
int i=10;
Test t= new Test();
t.printValue(i);
}
}
第3页共6页