1、运算符优先级问题,下面代码的结果是多少?(笔试)
[java] view plaincopy
package test;
public class Test {
public static void main(String[] args) {
int k = 0;
int ret = ++k + k++ + ++k + k;
// ret的值为多少
System.err.println(ret);
}
}
2、运算符问题,下面代码分别输出什么?(笔试)
[java] view plaincopy
package test;
public class Test {
public static void main(String[] args) {
int i1 = 10, i2 = 10;
System.err.println("i1 + i2 = " + i1 + i2);
System.err.println("i1 - i2 = " + i1 - i2);
System.err.println("i1 * i2 = " + i1 * i2);
System.err.println("i1 / i2 = " + i1 / i2);
}
}
3、下面代码的结果是什么?还是抛出异常?(笔试)
[java] view plaincopy
package test;
public class Test {
public void myMethod(String str) {
System.err.println("string");
}
public void myMethod(Object obj) {
System.err.println("object");
}
public static void main(String[] args) {
Test t = new Test();
t.myMethod(null);
}
}