image.png

    1. package com.atguigu.java4;
    2. import org.junit.Test;
    3. /*
    4. * 关于包装类使用的面试题
    5. *
    6. */
    7. public class InterviewTest {
    8. @Test
    9. public void test1(){
    10. Object o1 = true ? new Integer(1) : new Double(2.0);
    11. System.out.println(o1);//1.0 类型提升了成double型了
    12. }
    13. @Test
    14. public void test2(){
    15. Object o2;
    16. if(true)
    17. o2 = new Integer(1);
    18. else
    19. o2 = new Double(2.0);
    20. System.out.println(o2);//1
    21. }
    22. }