zoukankan      html  css  js  c++  java
  • OCJP-试题集合 | 对象的比较

    Boolean b1 = new Boolean(true);

    Boolean b2 = new Boolean(true);

    下面哪个能得到true的结果:

    A b1 == b2

    B b1.equals(b2)

    C b1&b2

    D b1 | b2

    E b1 && b2

    F b1 || b2

    [解答]:除了A,其他的都是true

    b1,b2两个是对象,两个对象的内容是相同的,但是两个对象所引用的地址是不同的,所以A不对,

    equals()就是用来比较对象的内容的,所以B正确,

    CDEF,JAVA中对象可以自动装箱、拆箱成为基本类型,

    [程序调试]

    package com.sam.test.object;

    /**
    * 对象的比较
    * @author Sam
    * @2013-11-7
    */
    public class CompileObject {

    public CompileObject() {
    // TODO Auto-generated constructor stub
    }

    public void paramInit(String args){
    }

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    //CompileObject demo = new CompileObject();
    Boolean b1 = new Boolean(true);
    Boolean b2 = new Boolean(true);

    System.out.println("b1== b2:"+(b1== b2));
    System.out.println("b1.equals(b2):"+b1.equals(b2));
    System.out.println("b1 & b2:"+(b1 & b2));
    System.out.println("b1 | b2:"+(b1 | b2));
    System.out.println("b1 && b2:"+(b1 && b2));
    System.out.println("b1 || b2:"+(b1 || b2));
    }

    }

    [控制台结果]

    b1== b2:false
    b1.equals(b2):true
    b1 & b2:true
    b1 | b2:true
    b1 && b2:true
    b1 || b2:true

  • 相关阅读:
    线程池execute执行顺序
    三个线程交替打印1到100
    mysql优化
    最大回文子串
    AOP实现日志收集和记录
    LoadingCache缓存使用(LoadingCache)
    springboot项目在idea中实现热部署
    idea破解
    linux常用命令
    Oracle的分条件计数COUNT(我的条件),由浅入深
  • 原文地址:https://www.cnblogs.com/MyITHome/p/3413448.html
Copyright © 2011-2022 走看看