是否已经参与过Java入门知识的自测?(点这里:Java编程基础自测题)
如果得分在80分以上,就来试试这个进阶版的自测吧,其中部分考题如下,答案附文后。(线上自测地址:【进阶版】Java面向对象编程基础自测题)
- 现在有如下一段代码
public class Test {
public int aMethod() {
static int i=0;
i++;
return i;
}
public static void main(String args[]) {
Test test = new Test();
test.aMethod();
int j = test.aMethod();
System.out.println(j);
}
}
将产生哪种结果:
A. Compilation will fail
B. Compilation will succeed and the program will print“0”
C. Compilation will succeed and the program will print“1”
D. Compilation will succeed and the program will print“2” - 如要在字符串s(内容为“welcome to mldn !! ”),中,发现字符’t’的位置,应该使用下面哪种方法?
A. mid(2,s);
B. charAt(2);
C. s.indexOf(‘t’);
D. indexOf(s,’v’); - 编译和运行下面代码可能会发生什么?
class Base {
private void amethod(int iBase) {
System.out.println(“Base.amethod”);
}
}
class Over extends Base {
public static void main(String args[]) {
Over o = new Over();
int iBase = 0 ;
o.amethod(iBase) ;
}
public void amethod(int iOver) {
System.out.println(“Over.amethod”);
}
}
A. Compile time error complaining that Base.amethod is private
B. Runntime error complaining that Base.amethod is private
C. Output of Base amethod
D. Output of Over.amethod - 现在有如下一段程序
class super {
String name ;
public super(String name) {
this.name = name ;
}
public void fun1() {
System.out.println(“this is class super !”+name);
}
}
class sub extends super {
public void fun1() {
System.out.println(“this is class sub !”+name);
}
}
class Test {
public static void main(String args[]) {
super s = new sub();
}
}
运行上面的程序可能会出现的结果?
A. this is class super !
B. this is class sub !
C. 编译时出错
D. 运行时出错 - 现在有如下一段程序
class Happy {
public static void main(String args[]) {
float [][] f1 = {{1.2f,2.3f},{4.5f,5.6f}} ;
Object oo = f1 ;
f1[1] = oo ;
System.out.println(“Best Wishes “+f1[1]);
}
}
该程序会出现何种效果?
A. {4.5,5.6}
B. 4.5
C. compilation error in line NO.5
D. exception - 在一个类文件中,导入包、类和打包是怎样的排列顺序?
A. package、import、class;
B. class、import、package
C. import、package、class
D. package、class、import
7.如果你试图编译并运行下列代码时可能会打印输出什么?
int i = 9 ;
switch(i) {
default:
System.out.println(“default”);
case 0 :
System.out.println(“zero”);
break ;
case 1 : System.out.println(“one”);
case 2 : System.out.println(“two”);
}
A. default
B. default , zero
C. error default clause not defined
D. no output displayed
8.当你编译下列代码可能会输出什么?
class Test {
static int i ;
public static void main(String args[]) {
System.out.println(i);
}
}
A. Error Variable i may not have been initialized
B. null
C. 1
D. 0
9.下面代码会存在什么问题?
public class MyClass {
public static void main(String arguments[]) {
amethod(arguments);
}
public void amethod(String[] arguments){
System.out.println(arguments);
System.out.println(arguments[1]);
}
}
A. 错误,void amethod()不是static类型
B. 错误,main()方法不正确
C. 错误,数组必须导入参数
D. 方法amethod()必须用String类型描述
10.为Demo类的一个无形式参数无返回值的方法method书写方法头,使得使用类名Demo作为前缀就可以调用它,该方法头的形式为?
A. static void method( )
B. public void method( )
C. final void method( )
D. abstract void method( )
答案:ACDCC ABDAA 你答对了几道题呢?
线上自测地址:【进阶版】Java面向对象编程基础自测题