This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Majji's mock exam doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Majji Watch "Majji New topic
Author

Majji's mock exam doubt

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,

How the following code is giving true as output...

int i=10;
int j=10;
boolean b=false;
if(b=i==j)
System.out.println("true");
else
System.out.println("false");

as conditional operators have higer precedence i==j will be evaluated and returns true ,but b is defined as false,so
if(b=....) returns false ..please can anybody help me..thanks in advance
regds
krishna
Savithri Devaraj
Ranch Hand

Joined: Jun 26, 2000
Posts: 103
Originally posted by krishna:
Hi,

How the following code is giving true as output...

int i=10;
int j=10;
boolean b=false;
if(b=i==j)
System.out.println("true");
else
System.out.println("false");

as conditional operators have higer precedence i==j will be evaluated and returns true ,but b is defined as false,so
if(b=....) returns false ..please can anybody help me..thanks in advance
regds
krishna

since i==j returns true, that is assigned to b. Assignment b=true returns true,and hence the answer
Savithri
[This message has been edited by Savithri Devaraj (edited August 17, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Majji's mock exam doubt
 
Similar Threads
SCJP Question
a question about if statement
Presidence in an IF statement
SCJP Question
operators