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]