Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Dry run this java prog ? and give the result

public static void main(String []args){ Integer i=new Integer(128); int e=128; if(i==e){ System.out.println("Hello World" ); } else { System.out.println("no problem"); } }

user-image
Question added by Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date Posted: 2013/12/26
Preetham D
by Preetham D , Software Engineer / Senior Software Engineer , Mindtree

O/P: Hello World

 

1) We would be able to compile it only if you put this code inside a valid class .

2) As others mentioned, when you run it it will print "Hello World".

 

3) We may also use i.equals(e) instead of i==e

4) We cannot use e.equals(i) , however we can use e==i

 

Mr. Shahnawaz, any particular reason for this question/ is the answer "Hello World" is wrong ?

 

Thanks

 

 

 

Daanish Rumani
by Daanish Rumani , Product Manager , Publicis Sapient

Answer: no problem

 

i.equals(e) should have been used

ofcourse "Hello World"  becoz reference ID128 is passed into variable i .

Usman Liaqat
by Usman Liaqat , Principal Software Engineer , Soliton Technologies

Is it to gain the points only ?

Ofcourse : Hello World

Md. Kaium Hossain
by Md. Kaium Hossain , Assistant Programmer , ERA Info Tech Ltd.

Answer: Hello World

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.