Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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 ajoutée par Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date de publication: 2013/12/26
Preetham D
par 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
par 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
par Usman Liaqat , Principal Software Engineer , Soliton Technologies

Is it to gain the points only ?

Ofcourse : Hello World

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

Answer: Hello World

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?