Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrapper Classes

 
sampath garapati
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone of you please give me the result for the below code and explain why. I thought the result was false and true.

public class wrappers {
public static void main(String [] ar){
Integer a,b,c=2;
a=new Integer(3);
b=new Integer(4);
c*=a+b;
int d=14;
System.out.println(c==d);
System.out.println(c.equals(d));
}
}


Thanks in advance.
Sampath
 
agrah upadhyay
Ranch Hand
Posts: 579
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You yuorself can get result while compiling............if you have any doubt,welcome!
 
Richard Mendoza
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First and foremost, your program doesn't compile so how can you say that the result is false.

Please make your program runnable first.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should run in java 1.5
 
sampath garapati
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.

May be this will run in java 1.5


sampath
 
haritha yellapu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Halo Sampath!

i could execute ur program n the o/p
is:
true
true

i would shortly get back to u with xplaination.

regards,
Haritha.
 
Karu Raj
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code will not compile in JDK1.4

Compilor error
 
Lalitha Gottumukkula
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here, c==d is equivalent to c.intValue()==d

This is because of Autoboxing/Unboxing feature present in java 1.5

Hope this helps.

- Lalitha.
 
haritha yellapu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!

what lalitha has written is true!
its bcoz of autoboxing feature the comparision
is true n it is only in java1.5.


regards,
Haritha.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic