What is the difference between identity and equality in OOP?
identity: a variable holds the same instance as another variable. equality: two distinct objects can be used interchangeably. they often have the same id. Identity For example: Integer a = new Integer(1); Integer b = a; a is identical to b. In Java, identity is tested with ==. For example, if( a == b ). … Read more