• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

boolean question from John Junt Mock Exam

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic