1、運(yùn)算符優(yōu)先級問題,下面代碼的結(jié)果是多少?(筆試)
[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、運(yùn)算符問題,下面代碼分別輸出什么?(筆試)
[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、下面代碼的結(jié)果是什么?還是拋出異常?(筆試)
[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);
}
}