上海某商城公司Java开发笔试题

记录自己遇到的笔试面试题

作为20届应届生,来上海找工作已经快一个月了,期间经历了大大小小十多家公司的面试,深刻认识到自己基础知识的不牢,在这里分享自己遇到的笔试题和面试题,供大家参考。(HR说10道选择题,错四道以上就无法进行下一轮面试,大家可以做着试一试,答案在最后)

第一题 :请从下列代码运行结果中选择正确的一项()

public class first {
    public static void main(String[] args){
        int i = 0;
       addTwo(i++);
        System.out.println(i);
    }
    static void addTwo(int i){
        i += 2;
    }
}

A :0 B :1 C: 2 D:3

第二题 :下面哪些是Java关键字?(多选)
a 、default
b、 NULL
c、String
d、throws
e、 long
f、 true

第三题 :编译并运行下面的程序,结果是什么?

public class MyClass {
    public static void main(String[] args) {
        String s = "Java 您好";
        System.out.println(s.length);
    }
}

请选择正确答案:
a :9 b: 7 c:11 d:编译错误

第四题 :编译并运行下面代码,请选择描述正确定的项。

public class RuiguClass {
    int i = 10;
    private static float pi = 3.0f;  //(1)

    public static void main(String[] args) {
        public int i = 20;      //(2)
        final double d = 4.0d;  //(3)
        System.out.println(i+d+pi);
    }
}

a: 编译正确,输出结果为28.0
b:编译错误,(1)处有错误
c:编译错误,(2)处有错误
d:编译错误,(3)处有错误

第五题:下面程序代码运行结果是什么?

class MyTest extends Test{
     public MyTest(){
         System.out.println("S2");
     }
}
public class Test{
    public static void main(String[] args) {
        new MyTest();
    }
    public Test(){
        System.out.println("S1");
    }
}

选择正确的答案: a:S1 b:S2 c:S1S2 d:S2S1

第六题 :编译并运行下面程序代码,请选择正确的输出结果:

public class MyClass1 {
    public static void main(String[] args) {
        List list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        List list2 = new LinkedList(list);
        list.addAll(list2);
        list2 = list.subList(2,5);  //此方法表示截取list2下标为2到4的数,即[2,5)
        list2.clear();
        System.out.println(list);
    }
}

a:[1,3,2] b:[1,3,3,2] c:[1,3,2,1,3,2]
d:[3,1,2] e:[3,1,1,2] f:以上都不对

第七题:编译并运行下面的程序,其结果是什么?

public class MyClass2 {
    public static void main(String[] args) {
        String str1 = "str1";
        String str2 = "str2";
        String str3 = "str3";
        str1.concat(str2);
        System.out.println(str3.concat(str1));
    }
}

a:代码不能通过编译,因为表达式str3.concat(str1)不是println()函数的合法参数
b:程序在运行时会打印str3str1str2
c: 程序在运行时将会打印str3
d:程序在运行时将会打印str3str1
e:程序在运行时将会打印str3str2

第八题 :What is the returned by “abcd” instanceof Object ? (“abcd” instanceof Object 返回结果是什么?)
a:“abcd” b:true c:false d:String

第九题 :Java的Web应用中,当把来自客户机的HTTP请求委托给Servlet时,会调用HttpServlet的哪个方法?请选择正确答案。
a:service
b:doGet
c:doPost
d:init
第十题 :运行下面代码,将会输出什么?

public class MyClass3 extends Thread{
    public void run(){
        try {
          for (int i = 1;i< 5;i++){
              System.out.println(i+" ");
              if(i>2) interrupt();
              sleep(1000);
              if (interrupted()) break;
          }
        }catch (InterruptedException e){
            System.out.println("caught");
        }
        }

    public static void main(String[] args) {
        MyClass3 my = new MyClass3();
        my.start();
    }
}

请选择正确的答案: a:1 b:1 2 c:1 2 3 d:1 caught
e:1 2 caught f:1 2 3 caught g:以上都不是

答案:

  1. B (注意addTwo()是有参无返回类型)
  2. a,d,e,f
    java关键字有:(注意boolean包含false和true)
    在这里插入图片描述
  3. 选d string是length()方法 ,而数组是length方法
  4. c
  5. c
  6. f (这题巨坑,最后输出是[1,2,3] ,注意在list2没有被clear()之前list存的数是[1,2,3,1,2,3] ,而list2的值为[3,1,2] ,所以list2被clear()之后相当于把list里面的3,1,2去掉了)
  7. d
  8. b (instanceof 测试它左边的对象是否是它右边类的实例,返回boolean类型数据)
  9. a
    10.f
    注解: interrupt()方法能中断目标线程
    isInterrupted()能够返回目标线程的中断状态
    interrupted()将清除当前线程的中断状态,并且返回它之前的值,这是清除中断状态的唯一方法.

结束语

我的github地址:https://github.com/object-cai
自己的毕设和做的项目都已经上传!
码字不易,点波关注不迷路,后续会继续分享被问到的面试题! 直到找到java开发工作岗位为止!

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值