1、运算符优先级问题,下面代码的结果是多少?(笔试)
- public class Test {
- public static void main(String[] args) {
- int k = 0;
- int ret = ++k + k++ + ++k + k;
- // ret的值为多少
- System.err.println(ret);
- }
- }
2、运算符问题,下面代码分别输出什么?(笔试)
- 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、下面代码的结果是什么?还是抛出异常?(笔试)
- 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);
- }
- }
4、假设今天是9月8日,下面代码输出什么?(笔试)
- import java.util.Date;
- public class Test {
- public static void main(String[] args) {
- Date date = new Date();
- System.err.println(date.getMonth() + " " + date.getDate());
- }
- }
5、下面代码的输出结果是什么?
- public class Test {
- public static void main(String[] args) {
- double val = 11.5;
- System.err.println(Math.round(val));
- System.err.println(Math.floor(val));
- System.err.println(Math.ceil(val));
- }
- }
6、输出的结果是什么?
- public class Test {
- public static void main(String[] args) {
- System.err.println(new Test().method1());
- System.err.println(new Test().method2());
- }
- public int method1() {
- int x = 1;
- try {
- return x;
- } finally {
- ++x;
- }
- }
- public int method2() {
- int x = 1;
- try {
- return x;
- } finally {
- return ++x;
- }
- }
- }
这样呢?输出什么
- public class Test {
- public static void main(String[] args) {
- System.out.println(method());
- }
- public static boolean method() {
- try {
- return true;
- } finally {
- return false;
- }
- }
- }