20200305----大厂笔试2 笔记

1.阿里
下列java程序的输出结果为()

public class Example{
	String str = new String("hello");
	char[] ch= {'a','b'};
	public static void main(String args[){
		Example ex = new Example();
		ex.change(ex.str,ex.ch);
		System.out.print(ex.str+" and ");
		System.out.print(ex.ch);
	}
	public void change(String str,char ch[]){
		str = "test ok";
		ch[0]= 'c';
	}
}

A.hello and ab
B.hello and cb
C.hello and a
D.test ok and ab
E.test ok and cb
F.test ok and c

  • 考察点:
    属性and方法
    方法存储and方法执行
    方法的形参和实参
    String类对象的创建
    String的不可变特性
String str = new String("hello");

创建的是两个String对象

2.阿里
有关下述Java代码描述正确的选项是()

public class TestClass {
	private static void testMethod(){
		System.out.printin("testMethod");
	}
	public static void main(String[ args) {
		((TestClass)null).testMethod();
	}
}

A.编译不通过
B.编译通过运行异常报NullPointerException
C.编译通过运行异常报lgalArgumentException
D.编译通过运行异常报NoSuchMethodException
E.编译通过运行异常报Exception
F.运行正常输出testMethod

  • 考察点
    • 多态
      1.向上向下转型
    • 关键点:static–静态
      1.修饰类成员–属性、方法、内部类、块(构造方法不可以修饰)
      2.特点:在类加载的时候出初始化、类和对象可以共享所以通过类名可以直接调用

3.腾讯
在Java语言中
如果"xyz"没有被创建过
执行String s = new String(“xyz”);后
创建了几个String object?
A.1
B.2
C.3
D.4

4.腾讯
numberList是- - 个顺序容器,
以下代码执行后,numberList里的 元素依次为?

List<Integer> numberList = new ArrayList();
numberList.add(2);
numberList.add(4);
numberList.add(1);
numberList.add(3);
numberList.add(5);
for(int i=0;i<numberList.size();++i){
	int V = numberList.get(i);
	if(v%2 == 0){
		numberList.remove(i);
	}
}

A.2,4,1,3,5
B.2,1,3,5
C.4,1,3,5
D.1,3,5

  • 考察点

    • 集合
      1.集合的分支体系
      Collection Map
      List Set

    List:ArrayList(数组 控制地址改变 扩容 删除)
    LinkedList(链表 Node对象 插入 删除)
    Set:无序无重复 Hash Tree
    Map:键值对 便于查找

  • 分析:
    集合初始为[2,4,1,3,5]
    i = 0 时 size = 5 get(i)取值 v = 2 下标为0的值被删除掉 集合长度变为4,集合变为[4,1,3,5] i = 1时,v取值为1,之后的都删不掉。

i      size           v          v%2==0?             remove后
0       5             2          成立--删除          [4,1,3,5]
1       4             1          不成立              [4,1,3,5]
2       4             3          不成立              [4,1,3,5]
3       4             3          不成立              [4,1,3,5]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值