Java进阶自测:面向对象基础知识你都掌握了吗?

本文提供了Java编程的挑战性题目及答案,涵盖编译错误、运行时错误、面向对象概念等多个方面,帮助读者深入理解Java语言特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

是否已经参与过Java入门知识的自测?(点这里:Java编程基础自测题
如果得分在80分以上,就来试试这个进阶版的自测吧,其中部分考题如下,答案附文后。(线上自测地址:【进阶版】Java面向对象编程基础自测题

  1. 现在有如下一段代码
    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”
  2. 如要在字符串s(内容为“welcome to mldn !! ”),中,发现字符’t’的位置,应该使用下面哪种方法?
    A. mid(2,s);
    B. charAt(2);
    C. s.indexOf(‘t’);
    D. indexOf(s,’v’);
  3. 编译和运行下面代码可能会发生什么?
    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
  4. 现在有如下一段程序
    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. 运行时出错
  5. 现在有如下一段程序
    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
  6. 在一个类文件中,导入包、类和打包是怎样的排列顺序?
    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面向对象编程基础自测题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值