Wednesday, April 1, 2009

Puzzle-12 Object or Value

Language – Java | Type – Concept | Last date 05-Apr-2009 12:00 p.m. IST | Points 2

We all know that ‘==’ operator check for Object reference equality. It’s not supposed to compare values. That is why I was bugged when I tried the code below and got the ‘impossible output’. Can you tell me why?
package com.twisters;
class IntegerEquality{

public static void main(String args[]){
Integer first
= 100;
Integer second
= 100;
if(first == second)
System.out.println(“This is impossible
System.out.println(“Everything is as expected out here.”)
Got an answer? Why don't you leave it here.

No comments:

Post a Comment

Solution for this question?