关于java的几道小题2

来源:百度知道 编辑:UC知道 时间:2024/06/21 11:13:12
10.欲构造ArrayList类的一个实例,此类继承了List接口,
下列哪个方法是正确的?
A ArrayList myList=new Object ();
B List myList=new ArrayList ();
C ArrayList myList=new List ();
D List myList=new List ();
11.下列代码如何使成员变量m被函数fun()直接访问?
class Test{
private int m;
public static void fun(){
//some code...
}
}
A 将 pricate int m 改为 protected int m
B 将 ...............改为 public int m
C ...................... static int m
D ...................... int m
12. 下面代码段中,执行之后i 和j 的值是什么?
int i = 1;
int j;
j = i++;
A 1,1 B 1,2 C 2,1 D 2,2
13.在如下源代文件Test.Java中,哪个是正确的类定义?
A
public class test{
public int x = 0;
public test(int x)
{
this.x = x;
}
}
B
public class Test{
public int x=0;
public void Test(int x){
this.x = x;
}
}
C
public class Test extends T1,T2{
public int x = 0;
public Test(int x){

10.欲构造ArrayList类的一个实例,此类继承了List接口,
下列哪个方法是正确的?
A ArrayList myList=new Object ();
B List myList=new ArrayList ();
C ArrayList myList=new List ();
D List myList=new List ();
答案:B(这是体现 JAVA的多态性,此类题目记住一个公式:类A是父类,类B为子类,A a=new B();永远正确~~当时我们教师就是这么教的,呵呵~~)

11.下列代码如何使成员变量m被函数fun()直接访问?
class Test{
private int m;
public static void fun(){
//some code...
}
}
A 将 pricate int m 改为 protected int m
B 将 ...............改为 public int m
C ...................... static int m
D ...................... int m
答案:C

12. 下面代码段中,执行之后i 和j 的值是什么?
int i = 1;
int j;
j = i++;
A 1,1 B 1,2 C 2,1 D 2,2
答案:c(i=2,j=1)

13.在如下源代文件Test.Java中,哪个是正确的类定义?
A
public class test{//类名要和文件名相同
public int x = 0;
public test(int x)
{
this.x = x;
}
}
B
public class Test{
public int x=0;
public void Test(int x){//在定义构造函数时不需要说明数据类型