Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What will be the output of the program (in jdk1.6 or above)?

public class BoolTest { public static void main(String [] args) { Boolean b1 = new Boolean("false"); boolean b2; b2 = b1.booleanValue(); if (!b2) { b2 = true; System.out.print("x "); } if (b1 & b2) /* Line13 */ { System.out.print("y "); } System.out.println("z"); } }

user-image
Question added by Faten Almajaly
Date Posted: 2014/06/23
Fahad Zulfiqar
by Fahad Zulfiqar , Intern , PTCL

x z is the output

Emad Mohammed said abdalla
by Emad Mohammed said abdalla , ERP & IT Software, operation general manager . , AL DOHA Company

the output will X Z

wahed mohammed abdul
by wahed mohammed abdul , SAP Security Consultant , Accenture Solutions Pvt ltd

if(!b2) means If(!false)=> if(True) => print x 

now, b1=false, b2=true 

line13: if(b1 &b2) => if(false & true) => false , so it skips if condition

print z .

 Output:  xz

Khalid Ahmed Budnar
by Khalid Ahmed Budnar , Manager IT Projects , Qatar Airways - HIA

xz

More Questions Like This