• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

boolean question from John Junt Mock Exam

 
may leung
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
boolean flag = false;
if (flag = true) {
System.out.println("true");
} else {
System.out.println("false");
}
a true is printed to standard out
b false is printed to standard out
c An exception is raised
d Nothing happens
The ans is d, But I think the ans should be A. Can anyone tell me the true?
 
sasi dhulipala
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
true is being printed on my sys. because the if statement
if (flag = true) is assigning true to flag and the enitre value of the expression becomes true making if to pass through and print
"true".

Sasidhar

[This message has been edited by sasi dhulipala (edited January 09, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic